Observable拆解中的Promise / Deferred代码

时间:2018-04-25 15:58:52

标签: angular rxjs observable

我有一个应用,我需要在Observable的拆解中执行一些延迟代码,但无法找到等待延迟代码执行的方法。

let observable = new Observable(subscriber => {
    setTimeout(() => subscriber.next('Hello World'), 3000);

    return () => {
        let promise = new Promise(resolve => {
            setTimeout(() => resolve(), 5000);
        });
    };
});

let subscription = observable.subscribe(next => console.log(next));

// So here the teardown callback will be called.
// I want to find a way to wait for the Promise to resolve or reject.
subscription.unsubscribe();

所以unsubscribe似乎不接受任何争论而且什么也不返回。

关于如何获取Observable的拆解功能中的promise变量的任何想法?

0 个答案:

没有答案