public static LTTask <T> FromCanceled <T>(CancellationToken token) { var tcs = new LTTaskCompletionSource <T>(); tcs.TrySetException(new OperationCanceledException(token)); return(tcs.Task); }
public static LTTask <T> FromException <T>(Exception ex) { var tcs = new LTTaskCompletionSource <T>(); tcs.TrySetException(ex); return(tcs.Task); }
public static LTTask FromException(Exception ex) { LTTaskCompletionSource tcs = new LTTaskCompletionSource(); tcs.TrySetException(ex); return(tcs.Task); }
/// <summary> /// Marks the task as successfully completed. /// </summary> public void SetResult() { if (moveNext == null) { } else { if (this.tcs == null) { this.tcs = new LTTaskCompletionSource(); } this.tcs.TrySetResult(); } }
/// <summary> /// Schedules the state machine to proceed to the next action when the specified awaiter completes. This method can be called from partially trusted code. /// </summary> /// <typeparam name="TAwaiter">The awaiter.</typeparam> /// <typeparam name="TStateMachine">The state machine.</typeparam> /// <param name="awaiter">The type of the awaiter.</param> /// <param name="stateMachine">The type of the state machine.</param> public void AwaitUnsafeOnCompleted <TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { if (moveNext == null) { if (this.tcs == null) { this.tcs = new LTTaskCompletionSource(); } var runner = new MoveNextRunner <TStateMachine>(); moveNext = runner.Run; runner.StateMachine = stateMachine; } awaiter.UnsafeOnCompleted(moveNext); }
/// <summary> /// Marks the task as failed and binds the specified exception to the task. /// </summary> /// <param name="exception"></param> public void SetException(Exception exception) { if (this.tcs == null) { this.tcs = new LTTaskCompletionSource(); } if (exception is OperationCanceledException ex) { this.tcs.TrySetCanceled(ex); } else { this.tcs.TrySetException(exception); } }