Microsoft.Azure.Storage.Core.Util.CancellableAsyncResultTaskWrapper
This class is designed to bridge the gap between async and APM.
Specifically, if you have a Task-based async method and you want to wrap Begin() and End() methods around it, that's
what this class is for.
Usually, this is trivial with normal Tasks, but because we use our custom 'ICancellableAsyncResult' rather than 'IAsyncResult',
we need this custom class.
Sample usage, assuming we already have an "DoThingAsync(CancellationToken token)" method that returns a Task:
public virtual ICancellableAsyncResult BeginDoThing(AsyncCallback callback, object state)
{
return CancellableAsyncResultTaskWrapper.Create(token => DoThingAsync(token), callback, state);
}
public virtual void EndDoThing(IAsyncResult asyncResult)
{
((CancellableAsyncResultTaskWrapper)asyncResult).Wait();
}
protected CancellableAsyncResultTaskWrapper()
Creates a new ICancellableAsyncResult task wrapper object.
public static ICancellableAsyncResult Create(Func<CancellationToken, Task> generateTask, AsyncCallback callback, object state)
public static ICancellableAsyncResult Create<T>(Func<CancellationToken, Task<T>> generateTask, AsyncCallback callback, object state)