Skip to content

delayWhen doesn't emit when the duration selector is empty() #3663

@Airblader

Description

@Airblader
Contributor

RxJS version: 6.1.0

Code to reproduce:

of(42).pipe(delayWhen(() => empty()))
  .subscribe(console.log);

Expected behavior:

This should log 42 immediately, as empty completes immediately which according to the docs should suffice even if the duration selector doesn't emit:

The source value is emitted on the output Observable only when the duration Observable emits a value or completes.

Actual behavior:

The observable completes without emission.

Activity

Airblader

Airblader commented on May 7, 2018

@Airblader
ContributorAuthor
of(42).pipe(delayWhen(() => empty().delay(0)))
  .subscribe(console.log);

does work as intended, so this seems to be an issue with the synchronicity.

cartant

cartant commented on May 7, 2018

@cartant
Collaborator

Looking at the existing implementation of delayWhen I found another problem. See #3665 if you are interested in fixing it whilst you are working with that particular operator's implementation. The fix should go into its own PR, of course.

Airblader

Airblader commented on May 7, 2018

@Airblader
ContributorAuthor

Yeah, I thought about this when first looking at it as well and then just forgot about it. I think my first PR attempt is no good. We'll need a better solution.

Airblader

Airblader commented on May 7, 2018

@Airblader
ContributorAuthor

OK, subscribeToResult memorizes the outerValue, so I think we can use that and be good. Updating the PR.

added 2 commits that reference this issue on May 7, 2018
1aa845d
2fbda3f
benlesh

benlesh commented on May 9, 2018

@benlesh
Member

The OP here isn't valid. of(42).pipe(() => empty()) should return empty, effectively... so there would be no emission.

Airblader

Airblader commented on May 9, 2018

@Airblader
ContributorAuthor

@benlesh Sorry, I messed up my OP when editing it. It's missing the delayWhen.

The correct example was

of(42).pipe(delayWhen(() => empty()))
  .subscribe(console.log);
added a commit that references this issue on May 21, 2018
d140498
added a commit that references this issue on May 31, 2018
2c43af7
locked as resolved and limited conversation to collaborators on Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @benlesh@Airblader@cartant

      Issue actions

        delayWhen doesn't emit when the duration selector is empty() · Issue #3663 · ReactiveX/rxjs