Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValueTaskAwaiter"/> struct.
 /// </summary>
 internal ValueTaskAwaiter(ref SystemValueTask awaitedTask)
 {
     this.AwaitedTask = ValueTaskAwaiter.TryGetTask(ref awaitedTask, out Task innerTask) ?
                        innerTask : null;
     this.Awaiter = awaitedTask.GetAwaiter();
     RuntimeProvider.TryGetFromSynchronizationContext(out CoyoteRuntime runtime);
     this.Runtime = runtime;
 }
Exemplo n.º 2
0
        /// <summary>
        ///		Wraps the object to ether an TaskT or an ValueTaskT
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static StringPromise ToPromise(this string data)
        {
#if ValueTask
            return(new StringPromise(data));
#else
            return(Promise.FromResult(data));
#endif
        }
Exemplo n.º 3
0
        /// <summary>
        ///		Wraps the object to ether an TaskT or an ValueTaskT
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ContextObjectPromise ToPromise(this ContextObject data)
        {
#if ValueTask
            return(new ContextObjectPromise(data));
#else
            return(Promise.FromResult(data));
#endif
        }
Exemplo n.º 4
0
        /// <summary>
        ///		Wraps the object to ether an TaskT or an ValueTaskT
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ItemExecutionPromise ToPromise(this IEnumerable <DocumentItemExecution> data)
        {
#if ValueTask
            return(new ItemExecutionPromise(data));
#else
            return(Promise.FromResult(data));
#endif
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValueTaskAwaiter"/> struct.
 /// </summary>
 private ValueTaskAwaiter(ref SystemValueTask awaitedTask, ref SystemCompiler.ValueTaskAwaiter awaiter)
 {
     this.AwaitedTask = ValueTaskAwaiter.TryGetTask(ref awaitedTask, out Task innerTask) ?
                        innerTask : null;
     this.Awaiter = awaiter;
     RuntimeProvider.TryGetFromSynchronizationContext(out CoyoteRuntime runtime);
     this.Runtime = runtime;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Tries to safely retrieve the payload of a value task if that payload is an asynchronous task.
        /// If the payload is a <see cref="SystemTasks.Sources.IValueTaskSource"/>, then it returns null.
        /// </summary>
        internal static bool TryGetTask(ref SystemValueTask task, out SystemTask payload)
        {
            // Access the payload through reflection.
            var field = task.GetType().GetField("_obj", BindingFlags.NonPublic | BindingFlags.Instance);

            payload = field?.GetValueDirect(__makeref(task)) as SystemTask;
            return(payload != null);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a value task that has completed with the specified exception.
 /// </summary>
 public static SystemTasks.ValueTask <TResult> FromException <TResult>(Exception exception) =>
 SystemValueTask.FromException <TResult>(exception);
Exemplo n.º 8
0
 /// <summary>
 /// Creates a value task that has completed due to cancellation with the specified cancellation token.
 /// </summary>
 public static SystemTasks.ValueTask <TResult> FromCanceled <TResult>(SystemCancellationToken cancellationToken) =>
 SystemValueTask.FromCanceled <TResult>(cancellationToken);
Exemplo n.º 9
0
 /// <summary>
 /// Creates a value task that has completed successfully with the specified result.
 /// </summary>
 public static SystemTasks.ValueTask <TResult> FromResult <TResult>(TResult result) =>
 SystemValueTask.FromResult(result);
Exemplo n.º 10
0
 public static Task <TResult> TimeoutAfter <TResult>(this ValueTask <TResult> task, int millisecondsTimeout)
 => task.AsTask().TimeoutAfter(TimeSpan.FromMilliseconds(millisecondsTimeout));
Exemplo n.º 11
0
 /// <summary>
 ///     Fires and forgets the task.
 /// </summary>
 /// <param name="_">
 ///     The task to discard.
 /// </param>
 public static void Discard <T>(this ValueTask <T> _)
 {
 }
Exemplo n.º 12
0
 public static async ValueTask <TResult> Then <T, TState, TResult>(this ValueTask <T> ValueTask, Func <T, TState, ValueTask <TResult> > next, TState state)
 => await next(await ValueTask, state);
Exemplo n.º 13
0
        public static async ValueTask Then(this ValueTask ValueTask, Func <ValueTask> next)
        {
            await ValueTask;

            await next();
        }
Exemplo n.º 14
0
        public static async ValueTask <TResult> Then <TResult>(this ValueTask ValueTask, ValueTask <TResult> next)
        {
            await ValueTask;

            return(await next);
        }
Exemplo n.º 15
0
 private static ValueTask <int> ReturnValueTask(ValueTask <int> vt) => vt;
Exemplo n.º 16
0
 public static async ValueTask Then <T, TState>(this ValueTask <T> ValueTask, Action <T, TState> next, TState state)
 => next(await ValueTask, state);
Exemplo n.º 17
0
 public static async ValueTask <TResult> Then <T, TResult>(this ValueTask <T> ValueTask, Func <T, TResult> next)
 => next(await ValueTask);
Exemplo n.º 18
0
        public static async ValueTask Then(this ValueTask ValueTask, Action next)
        {
            await ValueTask;

            next();
        }
Exemplo n.º 19
0
 /// <summary>
 ///     Fires and forgets the task.
 /// </summary>
 /// <param name="_">
 ///     The task to discard.
 /// </param>
 public static void Discard(this ValueTask _)
 {
 }
Exemplo n.º 20
0
        public static async ValueTask Then <TState>(this ValueTask ValueTask, Action <TState> next, TState state)
        {
            await ValueTask;

            next(state);
        }
Exemplo n.º 21
0
 public static Task TimeoutAfter(this ValueTask task, TimeSpan timeout)
 => task.AsTask().TimeoutAfter(timeout);
Exemplo n.º 22
0
        public static async ValueTask <TResult> Then <TResult>(this ValueTask ValueTask, Func <TResult> next)
        {
            await ValueTask;

            return(next());
        }
Exemplo n.º 23
0
 public static Task <TResult> TimeoutAfter <TResult>(this ValueTask <TResult> task, TimeSpan timeout)
 => task.AsTask().TimeoutAfter(timeout);
Exemplo n.º 24
0
        public static async ValueTask Then <TState>(this ValueTask ValueTask, Func <TState, ValueTask> next, TState state)
        {
            await ValueTask;

            await next(state);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Creates a value task that has completed due to cancellation with the specified cancellation token.
 /// </summary>
 public static SystemValueTask FromCanceled(SystemCancellationToken cancellationToken) =>
 SystemValueTask.FromCanceled(cancellationToken);
Exemplo n.º 26
0
        public static async ValueTask <TResult> Then <TState, TResult>(this ValueTask ValueTask, Func <TState, ValueTask <TResult> > next, TState state)
        {
            await ValueTask;

            return(await next(state));
        }
Exemplo n.º 27
0
 /// <summary>
 /// Creates a value task that has completed with the specified exception.
 /// </summary>
 public static SystemValueTask FromException(Exception exception) => SystemValueTask.FromException(exception);
Exemplo n.º 28
0
 public static async ValueTask Then <T>(this ValueTask <T> ValueTask, Func <T, ValueTask> next)
 => await next(await ValueTask);
Exemplo n.º 29
0
 /// <summary>Returns a value indicating whether this value is equal to a specified <see cref="ValueTask{TResult}"/> value.</summary>
 public bool Equals(ValueTask <TResult> other) =>
 _task != null || other._task != null ?
 _task == other._task :
 EqualityComparer <TResult> .Default.Equals(_result, other._result);
Exemplo n.º 30
0
 public static async ValueTask Then <T>(this ValueTask <T> ValueTask, Action <T> next)
 => next(await ValueTask);