Beispiel #1
0
 /// <summary>
 /// Awaits on the given task and once task finishes (irrespective of its state), disposes
 /// the given disposable instance. New task is NOT created.
 /// </summary>
 /// <param name="awaitOn">Task to await on. If not started, then it will started before it is awaited on.</param>
 /// <param name="disposeIt">Disposable instance</param>
 public static async Task AwaitNDisposeAsync(this Task awaitOn, IAsyncDisposable disposeIt)
 {
     await using (disposeIt.ConfigureAwait(false))
     {
         await awaitOn.StartIfNeeded().ConfigureAwait(false);
     }
 }
        public static ConfiguredAsyncDisposable WithContext(this IAsyncDisposable asyncDisposable)
        {
            if (asyncDisposable == null)
            {
                throw new ArgumentNullException(nameof(asyncDisposable));
            }

            return(asyncDisposable.ConfigureAwait(true));
        }
Beispiel #3
0
 internal static async ValueTask DisposeIfRequiredAsync(this IAsyncDisposable disposable, bool dispose)
 {
     if (dispose)
     {
         await using (disposable.ConfigureAwait(false))
         {
             //to dispose
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// Awaits on the given task and once task finishes (irrespective of its state), disposes
 /// the given disposable instance. Runs everything as a new task.
 /// </summary>
 /// <param name="awaitOn">Task to await on. If not started, then it will started before it is awaited on.</param>
 /// <param name="disposeIt">Disposable instance</param>
 public static Task AwaitNDispose(this Task awaitOn, IAsyncDisposable disposeIt)
 {
     return(Task.Run(async() =>
     {
         await using (disposeIt.ConfigureAwait(false))
         {
             await awaitOn.StartIfNeeded().ConfigureAwait(false);
         }
     }));
 }
Beispiel #5
0
 public static ConfiguredAsyncDisposable NoSync(this IAsyncDisposable task)
 {
     return(task.ConfigureAwait(false));
 }
 public static ConfiguredAsyncDisposable AnyContext(this IAsyncDisposable source)
 {
     return(source.ConfigureAwait(continueOnCapturedContext: false));
 }