I want to asynchronously dispose of a resource in the unsubscribe function of an observable. For example:
// rxjs 6
let observable = Observable.create(sub => {
let resource = new Resource();
return {
async unsubscribe() {
await resource.dispose();
}
}
};
The problem is that because the unsubscribe function isn't supposed to return a Promise, nothing will await it so the unsubscribe function will be "over early", before the resource is fully disposed of. This can cause behavior that shouldn't happen while the resource is being disposed of.
How do I deal with this?