I have a simple function like this that I'm expecting true
from. It creates an Observable
from true
, turns it into a promise, and await
s it:
async function returnTrue() {
return await of(true).toPromise();
}
var b = returnTrue();
console.log("b is: ", b);
When the value of b
is logged it logs:
b is:Promise {}
IIUC the other way to do this is to pipe
the observable like this:
function returnFalse() {
return of(false).pipe(map(b=>{
return b;
}));
}
const c = returnFalse();
console.log('Return value c: ', c);
In this case the value logged is:
Return value c:
Observable {_isScalar: false, source: {…}, operator: {…}}
Thoughts?
Summary
Summarized the answers an thinking on this in order to do synchronous programming with RxJS Observables: