Is there a way to await for the first value returned from a subscribe call?
For example, in the following:
async getValue(...) {
myObs$ = ...
let val = await myObs$.pipe(first()).toPromise()
myObs$.subscribe(val => {
this.value = val
})
return val
}
The async function will return a Promise of val, but I also want to subscribe and get a data member value that will be updated whenever the observable myObs$ emits a new value.
My question: is there away to return a Promise without calling the line with the first() call and just wait for the first time I get the result in subscribe?
await myObs$.pipe(first()).toPromise()after you subscribe. - martintoPromiseeffects an implicit subscription to the observable upon which it's called. - cartantsubscribefor the first time. This would be the reactive way to do it. - frido