Skip to content

debounce does not handle scalar observables correctly #3232

Closed
@Medo42

Description

RxJS version:
5.5.2, but the offending code is unchanged in 5.5.6

Code to reproduce:

// Not working
Observable.interval(100).pipe(
    debounce(i => Observable.of(0))
).subscribe(console.log);

// Working
Observable.interval(100).pipe(
    debounce(i => Observable.timer(0))
).subscribe(console.log);

Expected behavior:

The debounce should act as a no-op.

Actual behavior:

There is an error:

ERROR TypeError: Cannot read property 'closed' of null
    at DebounceSubscriber._tryNext (debounce.js:102)

The line number refers to 5.5.2, it is this line: https://github.com/ReactiveX/rxjs/blob/5.5.6/src/operators/debounce.ts#L108

Additional information:

The call to subscribeToResult returns null if no subscription is necessary because the value can be immediately obtained, as in this case of a simple "scalar" observable. debounce should handle this return value properly.

The example code is useless of course. My actual use case only returned such an Observable in one case, depending on the value passed in. It is for a loading bar which should only show after at least 200ms of activity, but should be hidden immediately once activity stops.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions