I've an app where I need to execute some deferred code inside an Observable's teardown but can't find a way to wait for this deferred code to be executed.
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();
So unsubscribe
seems to accept no argument and returns nothing.
Any idea on how to get the promise
variable which is inside the Observable's teardown function?