Rxjs: toPromise not work

Created on 10 Apr 2017  路  5Comments  路  Source: ReactiveX/rxjs

RxJS version: 5.0.1

Code to reproduce: https://jsfiddle.net/tossp/nmf9jg32/

Most helpful comment

toPromise is essentially observable.last().subscribe()

If you add .take(1) just before you call toPromise then things will start to work.

ie
example.do((value)=>console.log('do!!!',value)).take(1).toPromise()

All 5 comments

toPromise is essentially observable.last().subscribe()

If you add .take(1) just before you call toPromise then things will start to work.

ie
example.do((value)=>console.log('do!!!',value)).take(1).toPromise()

Thank you so much

I just spend 3 hours fighting toPromise returning _nothing_ and wondering why until I found this issue.
This behaviour was not obvious (to me) when reading the RxJs docs. Still trying to wrap my head around why take(1) solved it for me as well.

@cjk toPromise will never resolve until the observable it is sourced from calls complete. So if you bind to a keyboard event Observable.fromEvent(document, 'onload'), that observable will never complete, unless you force it to through something like take(1).

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benlesh picture benlesh  路  3Comments

marcusradell picture marcusradell  路  4Comments

giovannicandido picture giovannicandido  路  4Comments

dooreelko picture dooreelko  路  3Comments

benlesh picture benlesh  路  3Comments