Async Disposable.Create

Viewed 1838

Disposable.Create require an Action as parameter. The Action is run when the Rx subscription is being disposed.

When disposing a Rx subscription I’d like to run some asynchronous clean up code, however using async () => with Action is identical to async void, which I’d like to avoid. For more details on why I want to avoid this, see here.

Is it possible to create something like a Disposable.AsyncCreate, which accepts Func<Task> rather than Action. If so how should I use it as part of a CompositeDisposable?

Or are there other patterns for dealing with asynchronous Disposal?

2 Answers
Related