Beispiel #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;
 }
Beispiel #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
        }
Beispiel #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
        }
Beispiel #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
        }
Beispiel #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;
 }
Beispiel #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);
        }
Beispiel #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);
Beispiel #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);
Beispiel #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);
Beispiel #10
0
 public static Task <TResult> TimeoutAfter <TResult>(this ValueTask <TResult> task, int millisecondsTimeout)
 => task.AsTask().TimeoutAfter(TimeSpan.FromMilliseconds(millisecondsTimeout));
Beispiel #11
0
 /// <summary>
 ///     Fires and forgets the task.
 /// </summary>
 /// <param name="_">
 ///     The task to discard.
 /// </param>
 public static void Discard <T>(this ValueTask <T> _)
 {
 }
Beispiel #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);
Beispiel #13
0
        public static async ValueTask Then(this ValueTask ValueTask, Func <ValueTask> next)
        {
            await ValueTask;

            await next();
        }
Beispiel #14
0
        public static async ValueTask <TResult> Then <TResult>(this ValueTask ValueTask, ValueTask <TResult> next)
        {
            await ValueTask;

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

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

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

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

            await next(state);
        }
Beispiel #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);
Beispiel #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));
        }
Beispiel #27
0
 /// <summary>
 /// Creates a value task that has completed with the specified exception.
 /// </summary>
 public static SystemValueTask FromException(Exception exception) => SystemValueTask.FromException(exception);
Beispiel #28
0
 public static async ValueTask Then <T>(this ValueTask <T> ValueTask, Func <T, ValueTask> next)
 => await next(await ValueTask);
Beispiel #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);
Beispiel #30
0
 public static async ValueTask Then <T>(this ValueTask <T> ValueTask, Action <T> next)
 => next(await ValueTask);