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

Observable's next action runs even when not taken #1370

Closed
pmowrer opened this issue Feb 20, 2016 · 8 comments
Closed

Observable's next action runs even when not taken #1370

pmowrer opened this issue Feb 20, 2016 · 8 comments

Comments

@pmowrer
Copy link

pmowrer commented Feb 20, 2016

The following seems like an injection bug starting in 5.0.0-beta.1:

createObserver(2)
  .startWith(1)
  .take(1)
  .subscribe(x => console.log(x));

function createObserver(value) {
  return Rx.Observable.create(observer => {
    console.log('in subscribe');
    observer.next(value);
    observer.complete();  

    return function () {
      console.log('disposed');
    };
  }); 
}

jsbin: http://jsbin.com/mebonun/6/edit?html,js,console

In RxJS 4.0.6 and in 5.0.0-beta.0, this works like I expect. The created observable is essentially ignored.

1

but as of 5.0.0-beta.1, the observable's subscribe and dispose functions are invoked:

1
"in subscribe"
"disposed"

It'd seem to make sense these don't get invoked, but I'm not certain about the expected behavior honestly.

@JaminFarr
Copy link

Possibly related, I've seen similar issues with take and repeat.

createObserver(2)
  .startWith(1)
  .repeat(5)
  .take(1)
  .subscribe(x => console.log(x));

output:

1
"in subscribe"
"disposed"
"in subscribe"
"disposed"
"in subscribe"
"disposed"
"in subscribe"
"disposed"
"in subscribe"
"disposed"

The repeat is re-subscribing even though the take has completed.

With the repeat directly after the .create the extra "in subscribe", "disposed" still happen but in a different order.

createObserver(2)
  .repeat(5)
  .startWith(1)
  .take(1)
  .subscribe(x => console.log(x));

Output:
1
"in subscribe"
"in subscribe"
"in subscribe"
"in subscribe"
"in subscribe"
"disposed"
"disposed"
"disposed"
"disposed"
"disposed"

Changing the the repeat count to -1 crashes the program.

@kwonoj
Copy link
Member

kwonoj commented Feb 24, 2016

Changing the the repeat count to -1 crashes the program

: For this specific issue, please refer #651 (comment). Long story in short, you may need subscribe on non-recursive, different scheduler for infinite (or largely enough) synchronous repeat.

@JaminFarr
Copy link

Thanks @kwonoj, I didn't realise that this had been covered. Yes, Schedulers have fixed the issue I was having.

@pmowrer apologies if I've derailed your thread.

@kwonoj
Copy link
Member

kwonoj commented Apr 8, 2016

@pmowrer I just tried snippet with current master, seems it's resolved. (Not sure why it was though). Would you mind to confirm on your end too?

@trxcllnt
Copy link
Member

trxcllnt commented Apr 8, 2016

@kwonoj this was likely fixed by #1516

@kwonoj
Copy link
Member

kwonoj commented Apr 8, 2016

@trxcllnt Thanks for clarification :) Let me close this issue for now then. @pmowrer , feel freely reopen if problem persists.

@kwonoj kwonoj closed this as completed Apr 8, 2016
@pmowrer
Copy link
Author

pmowrer commented May 26, 2016

I can confirm this is fixed on my end. Thanks @kwonoj!

@lock
Copy link

lock bot commented Jun 7, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants