I have disposable class with async methods.
class Gateway : IDisposable {
public Gateway() {}
public void Dispose() {}
public async Task<Data> Request1 () {...}
public async Task<Data> Request2 () {...}
public async Task<Data> Request3 () {...}
}
I need Dispose to await until all running requests are completed.
So, either I need to track of all running tasks, or use AsyncLock
from AsyncEx, or something else?
Updated
As I can see someone is afraid of blocking Dispose. Then we could make Task WaitForCompletionAsync()
or Task CancelAllAsync()
methods.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…