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

RxJs lastValueFrom scheduled asapScheduler strange behaviour #7241

Closed
nigrosimone opened this issue Apr 1, 2023 · 3 comments
Closed

RxJs lastValueFrom scheduled asapScheduler strange behaviour #7241

nigrosimone opened this issue Apr 1, 2023 · 3 comments

Comments

@nigrosimone
Copy link

nigrosimone commented Apr 1, 2023

Describe the bug

I have this stript for play with scheduled/asapScheduler but I found a strange behaviour in combination with lastValueFrom:

    import { of, lastValueFrom, scheduled, asapScheduler } from 'rxjs';
    
    const bbj = { foo: 'bar' };
    
    async function foo() {
      const result = await lastValueFrom(scheduled(of(bbj), asapScheduler));
      console.log(result);
      return result;
    }
    
    async function main() {
      await foo(); // 1° console log
      await foo(); // 2° console log
      await foo(); // 3° console log
    }
    
    document.getElementById('button').addEventListener('click', function () {
      main();
    });

the expected behaviour is on button click, 3 console log, eg.:

{foo: "bar"}
{foo: "bar"}
{foo: "bar"}

But on first click it produce NO console log

On second click it produce 5 console log:

{foo: "bar"}
{foo: "bar"}
{foo: "bar"}
{foo: "bar"}
{foo: "bar"}

and on third click, 1 console log:

{foo: "bar"}

Why not produce 3 console log on each click?

Expected behavior

3 console log on each click

{foo: "bar"}
{foo: "bar"}
{foo: "bar"}

Reproduction code

import { of, lastValueFrom, scheduled, asapScheduler } from 'rxjs';
    
    const bbj = { foo: 'bar' };
    
    async function foo() {
      const result = await lastValueFrom(scheduled(of(bbj), asapScheduler));
      console.log(result);
      return result;
    }
    
    async function main() {
      await foo(); // 1° console log
      await foo(); // 2° console log
      await foo(); // 3° console log
    }
    
    document.getElementById('button').addEventListener('click', function () {
      main();
    });

Reproduction URL

try online https://stackblitz.com/edit/rxjs-mkgftu?devtoolsheight=60&file=index.ts

Version

7

Environment

No response

Additional context

No response

nigrosimone added a commit to nigrosimone/ng-http-caching that referenced this issue Apr 1, 2023
@voliva
Copy link
Contributor

voliva commented Apr 3, 2023

It could be an issue on scheduled with synchronous values. It looks like for some reason on the first click the observable emits the value, but it doesn't complete the observable.

https://stackblitz.com/edit/rxjs-cwwznh?devtoolsheight=60&file=index.ts

@voliva
Copy link
Contributor

voliva commented Apr 3, 2023

I think this was fixed by #7198, not released yet as a patch.

I've bisected it by adding this test:

it('completes', (done) => {
    const input = of('a');
    scheduled(input, asapScheduler).subscribe({
      complete: done
    });
  });

on master and 7.x branch it's fixed, and before that merge it breaks.

@benlesh
Copy link
Member

benlesh commented Apr 26, 2023

This is confirmed fixed in the latest published version of RxJS (7.8.1)

@benlesh benlesh closed this as completed Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants