Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delayWhen should use an indefinite delay for notifiers that complete #3665

Open
cartant opened this issue May 7, 2018 · 9 comments
Open

delayWhen should use an indefinite delay for notifiers that complete #3665

cartant opened this issue May 7, 2018 · 9 comments
Assignees
Labels

Comments

@cartant
Copy link
Collaborator

@cartant cartant commented May 7, 2018

This issue's title has been changed, as the implementation of delayWhen is not correct - see the discussion below.

The original issue's description follows.

RxJS version: 6.1.0

Code to reproduce:

import { EMPTY, of } from "rxjs";
import { delay, delayWhen } from "rxjs/operators";

of(0).pipe(
    delayWhen(() => EMPTY.pipe(delay(0)))
).subscribe(console.log);

Expected behavior:

0 should be emitted and logged to the console.

Actual behavior:

Nothing is emitted and logged to the console.

If the of function is passed 1 instead of 0, 1 is logged to the console.

Additional information:

Looking at delayWhen, I can see another problem (other than #3663) with the implementation. If the value is falsy, and the notifier completes - rather than nexts - the value won't be emitted.

@benlesh

This comment has been minimized.

Copy link
Member

@benlesh benlesh commented May 9, 2018

So the semantics here seem off... The notifier completes without notifying, therefor the delay should last indefinitely. This isn't a bug with the library so much as it is with the usage.

@Airblader

This comment has been minimized.

Copy link
Contributor

@Airblader Airblader commented May 9, 2018

@benlesh The docs explicitly state that the notifier completing should cause the value to be emitted.

@benlesh

This comment has been minimized.

Copy link
Member

@benlesh benlesh commented May 21, 2018

🤦‍♂️

@benlesh

This comment has been minimized.

Copy link
Member

@benlesh benlesh commented May 21, 2018

Okay, so we need to fix the issue, but deprecate the behavior.

@Hyumiris

This comment has been minimized.

Copy link

@Hyumiris Hyumiris commented May 3, 2019

I have recently run into the same issue(s).

Regarding the deprecation

Even though there is a deprecation warning for Observable<never> this only works if the generated Observable is known to be of type never at compile time.
In every other case the deprecation warning isn't shown and the official documentation still doesn't mention anything about the depreciation.

Regarding the bug

The bug that the behaviour of the delayWhen operator depends on the truthiness of the source value persists as well.

Here is a more concise version of the reproduction code:

import { of, EMPTY } from 'rxjs'; 
import { delayWhen } from 'rxjs/operators';

of(true, false, 0, 1).pipe(
  delayWhen(() => EMPTY)
).subscribe(console.log);

// this logs:
// >> true
// >> 1
@BioPhoton

This comment has been minimized.

Copy link
Contributor

@BioPhoton BioPhoton commented Aug 12, 2019

@cartant how can we move forward with this?
Is this PR teambition/teambition-sdk#576 solving the iisue?

@xumepadismal

This comment has been minimized.

Copy link

@xumepadismal xumepadismal commented Dec 12, 2019

Hi guys! One more thought regarding the deprecation

Can someone explain to me why the deprecated version of delayWhen uses Observable<never> instead of Observable<void>? All the discussions is about notifiers that "complete without emit" whereas Observable<never> === "emit no items, never complete"...

@Airblader

This comment has been minimized.

Copy link
Contributor

@Airblader Airblader commented Dec 12, 2019

The generic is the type of the emitted values. void means it emits but without data, never means it never emits.

@xumepadismal

This comment has been minimized.

Copy link

@xumepadismal xumepadismal commented Dec 12, 2019

Ah got it... Thanks @Airblader!

So EMPTY and NEVER has identical type signatures and there is no way to distinguish them and that's why we get the problem described by @Hyumiris (about deprecation). Is it correct?

@cartant cartant changed the title delayWhen won't emit falsy values for notifiers that complete delayWhen should use an indefinite delay for notifiers that complete Feb 16, 2020
@cartant cartant self-assigned this Feb 16, 2020
@cartant cartant mentioned this issue Apr 4, 2020
0 of 2 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.