javascript - Observable.of turn async -


i'm mock http call wrapped observable. initial idea use observable.of similar promise.resolve, not seem work expected:

rx.observable.of('of1').subscribe(e => console.log(e));    console.log('of2');    rx.observable.from(promise.resolve('from1')).subscribe(e => console.log(e));    console.log('from2');
<script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.6/dist/global/rx.umd.js"></script>

it seems observable.of runs synchronously while rx.observable.from(promise.resolve('from1')) runs asynchronously (that want). long want test spinner displayed, synchronous call not option me.

there kind of solution when e.g. delay or set timer:

rx.observable.of('of1').delay(0).subscribe... 

but not me.

how can turn observable.of run asynchronously? converting promise seems overkill.

if want observable of behave differently can pass scheduler. use async scheduler make observable emit values call stack clear. code wise this:

rx.observable.of(1, 2, 3, rx.scheduler.async).subscribe(     (val) => console.log(val) );  console.log('first'); 

this log out:

//first //1 //2 //3 

working jsbin example here: http://jsbin.com/cunatiweqe/6/edit?js,console


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -