CoreTaskExtensionsFinallyTResult Method (TaskTResult, FuncTaskTResult, Task) |
Namespace: Rackspace.Threading
public static Task<TResult> Finally<TResult>( this Task<TResult> task, Func<Task<TResult>, Task> cleanupFunction )
Exception | Condition |
---|---|
ArgumentNullException |
If task is . -or- If cleanupFunction is . |
This code implements support for the following construct without requiring the use of /.
try { return await task.ConfigureAwait(false); } finally { await cleanupFunction(task).ConfigureAwait(false); }
This method ensures that exception information provided by a faulted or canceled task is not wrapped in an additional AggregateException.
Notes to Callers |
---|
Since the cleanupFunction is executed synchronously, this method should only be used for lightweight continuation functions. This restriction applies only to cleanupFunction itself, not to the Task returned by it. |