Skip to content

DelayQueue failed: behavior breaking change after RxJS from v6 to v7 #71

@huan

Description

@huan

The following code work as expected with RxJS@6:

concatMap(args => concat(
of(args), // emit first item right away
EMPTY.pipe(delay(this.period)), // delay next item
)),

It will add a delay between each item.

However, the above code does not work anymore after we upgrade to RxJS@7, it likes that all delay does not take effect anymore: all items will be emitted without any delay.

Problem: breaking changes from RxJS

After performed my google-fu, I found there's a "behavior of delay inconsistent with completions" (ReactiveX/rxjs#4249) created by @benlesh which talked about this behavior and there's also a PR named "fix(delay): emit complete notification as soon as possible" (ReactiveX/rxjs#4444) has implemented this change.

So that's the reason why our code break after upgrade to RxJS v7.

Solution

Use the following code to emit complete after the delay this.period.

concatMap(x => concat(
  of(x),
  timer(this.period).pipe(skip(1)),
)),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions