Ejemplo n.º 1
0
 public static async ValueTask <T> CatchAwait <T, TException>(this ValueTask <T> task, Func <TException, ValueTask <T>, ValueTask <T> > onFailure) where TException : Exception
 {
     try
     {
         return(await(task = task.Preserve()));
     }
     catch (TException e)
     {
         return(await onFailure(e, task));
     }
 }
Ejemplo n.º 2
0
 public static async ValueTask CatchAwait <TException>(this ValueTask task, Func <TException, ValueTask, ValueTask> onFailure) where TException : Exception
 {
     try
     {
         await(task = task.Preserve());
     }
     catch (TException e)
     {
         await onFailure(e, task);
     }
 }
Ejemplo n.º 3
0
 public static async ValueTask <T> Catch <T>(this ValueTask <T> task, Func <Exception, ValueTask <T>, T> onFailure)
 {
     try
     {
         return(await(task = task.Preserve()));
     }
     catch (Exception e)
     {
         return(onFailure(e, task));
     }
 }
Ejemplo n.º 4
0
 public static async ValueTask Catch(this ValueTask task, Action <Exception, ValueTask> onFailure)
 {
     try
     {
         await(task = task.Preserve());
     }
     catch (Exception e)
     {
         onFailure(e, task);
     }
 }
Ejemplo n.º 5
0
                public ValueTask <bool> MoveNextAsync()
                {
                    ValueTask <bool> valueTask = m_Source.MoveNextAsync();
                    ValueTask <bool> ret       = valueTask.Preserve();

                    Current = m_Selector(Task.Run(async() => {
                        await valueTask;
                        return(m_Source.Current);
                    }));
                    return(ret);
                }
Ejemplo n.º 6
0
 public static async ValueTask FinallyAwait(this ValueTask task, Func <ValueTask, ValueTask> onCompletion)
 {
     try
     {
         await(task = task.Preserve());
     }
     finally
     {
         await onCompletion(task);
     }
 }
Ejemplo n.º 7
0
 public static async ValueTask <T> FinallyAwait <T>(this ValueTask <T> task, Func <ValueTask <T>, ValueTask> onCompletion)
 {
     try
     {
         return(await(task = task.Preserve()));
     }
     finally
     {
         await onCompletion(task);
     }
 }
Ejemplo n.º 8
0
 public static async ValueTask <T> Finally <T>(this ValueTask <T> task, Action <ValueTask <T> > onCompletion)
 {
     try
     {
         return(await(task = task.Preserve()));
     }
     finally
     {
         onCompletion(task);
     }
 }
Ejemplo n.º 9
0
 public static async ValueTask <T> OnFailure <T, TException>(this ValueTask <T> task, Action <TException, ValueTask <T> > onFailure) where TException : Exception
 {
     try
     {
         return(await(task = task.Preserve()));
     }
     catch (TException e)
     {
         onFailure(e, task);
         throw;
     }
 }
Ejemplo n.º 10
0
        public static async ValueTask <T> OnFailureAwait <T>(this ValueTask <T> task, Func <Exception, ValueTask <T>, ValueTask> onFailure)
        {
            try
            {
                return(await(task = task.Preserve()));
            }
            catch (Exception e)
            {
                await onFailure(e, task);

                throw;
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Consumes a ValueTask and allows it to be recycled, if applicable.  Useful for fire-and-forget calls to async methods within async methods.
 /// NOTE: APIs should not generally return <see cref="ValueTask{T}"/> if callers aren't 99.9999% likely to await the result immediately.
 /// </summary>
 /// <typeparam name="T">The type of value produced by the <paramref name="task"/>.</typeparam>
 /// <param name="task">The task whose result is to be ignored.</param>
 public static void Forget <T>(this ValueTask <T> task) => task.Preserve();
Ejemplo n.º 12
0
 public static void Forget(this ValueTask task)
 {
     task.Preserve();
 }
Ejemplo n.º 13
0
 public static void Forget(this ValueTask valueTask) => valueTask.Preserve();