/// <summary> /// Starts an asynchronous task with a new <see cref="AsyncContext"/>. /// </summary> /// <param name="function">A function starting and returning an asynchronous task.</param> /// <param name="cancellationToken">A cancellation token.</param> /// <returns>The asynchronous task that was started.</returns> /// <remarks> /// <para>This is equivalent to doing <c>return function(cancellationToken);</c> except that the task starts with a new <see cref="AsyncContext"/></para> /// </remarks> public static Task <TResult> WithNewContext <TResult>(Func <CancellationToken, Task <TResult> > function, CancellationToken cancellationToken) => AsyncContext.WithNewContextInternal(function, cancellationToken);
/// <summary> /// Starts an asynchronous task with a new <see cref="AsyncContext"/>. /// </summary> /// <param name="function">A function starting and returning an asynchronous task.</param> /// <param name="cancellationToken">A cancellation token.</param> /// <returns>The asynchronous task that was started.</returns> /// <remarks> /// <para>This is equivalent to doing <c>return function(cancellationToken);</c> except that the task starts with a new <see cref="AsyncContext"/></para> /// </remarks> public static Task WithNewContext(Func <CancellationToken, Task> function, CancellationToken cancellationToken) => AsyncContext.WithNewContextInternal(function, cancellationToken);
/// <summary> /// Starts an asynchronous task with a new <see cref="AsyncContext"/>. /// </summary> /// <param name="function">A function starting and returning an asynchronous task.</param> /// <returns>The asynchronous task that was started.</returns> /// <remarks> /// <para>This is equivalent to doing <c>return function();</c> except that the task starts with a new <see cref="AsyncContext"/></para> /// </remarks> public static Task <TResult> WithNewContext <TResult>(Func <Task <TResult> > function) => AsyncContext.WithNewContextInternal(function);
// TODO: consider having overloads for arguments to avoid capturing // see ArgsVsCaptureAndStateMachine - it would be more efficient but requires a lot of code /// <summary> /// Starts an asynchronous task with a new <see cref="AsyncContext"/>. /// </summary> /// <param name="function">A function starting and returning an asynchronous task.</param> /// <returns>The asynchronous task that was started.</returns> /// <remarks> /// <para>This is equivalent to doing <c>return function();</c> except that the task starts with a new <see cref="AsyncContext"/></para> /// </remarks> public static Task WithNewContext(Func <Task> function) => AsyncContext.WithNewContextInternal(function);