Chatie / db

Database for Chatie
https://www.chatie.io
Apache License 2.0
0 stars 0 forks source link

Be aware about the BehaviorObservable.toPromise() not work as expected. #6

Closed huan closed 6 years ago

huan commented 6 years ago

We will expect it resolve immediately but it doesn't.

See: https://github.com/Reactive-Extensions/RxJS/issues/1088 - BehaviourSubject toPromise isn't working

UPDATE:

return new Promise((resolve, reject) => {
    let value;
    this.subscribe((x) => value = x, (err) => reject(err), () => resolve(value));
});
huan commented 6 years ago

SOLUTION:

await behaviorSubject.asObservable.first().toPromise()

The magic resides in the above first() which will make it work as expected.

ErraticFox commented 4 years ago

UPDATE: for anyone else viewing this later the solution would be:

await behaviorSubject.pipe(take(1)).toPromise()
huan commented 4 years ago

@ErraticFox Thanks! We are in the stage of RxJS 6 now! 🎉

PabloPerezAguilo commented 4 years ago

UPDATE: for anyone else viewing this later the solution would be:

await behaviorSubject.pipe(take(1)).toPromise()

Works! Thx! Not all hero wear capes.

ErraticFox commented 4 years ago

@PabloPerezAguilo just make sure to pay the good deed forward. :)