我有一个应用,我需要在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
变量的任何想法?