且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

可观察到的异步

更新时间:2022-03-29 09:36:05

如果您希望可观察对象的行为不同,则可以将其传递给调度程序.您可以使用异步调度程序,使调用堆栈一经清除就使可观察到的发射值. 明智的代码如下所示:

If you want an observable of to behave differently you can pass it a scheduler. You could use the async scheduler to make the observable emit values as soon as the call stack is clear. Code wise this would look like this:

Rx.Observable.of(1, 2, 3, Rx.Scheduler.async).subscribe(
    (val) => console.log(val)
);

console.log('first');

这将注销:

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

此处工作的jsbin示例: http://jsbin.com/cunatiweqe/6/edit ?js,控制台

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