Exemplo n.º 1
0
 /// <summary>
 /// Transitions the underlying <see cref="Task"/> into the
 /// <see cref="TaskStatus.RanToCompletion"/> state. The awaiting code is executed
 /// asynchronously so it won't block the caller of this method.
 /// </summary>
 /// <typeparam name="T">The type of the result.</typeparam>
 /// <param name="tcs"></param>
 /// <param name="result">The result value to bind to this <see cref="Task"/>.</param>
 public static void SetResultAsync <T>(this TaskCompletionSource <T> tcs, T result)
 {
     FakeSynchronizationContext.Execute(() => tcs.SetResult(result));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Attempts to transition the underlying <see cref="Task"/> into the
 /// <see cref="TaskStatus.RanToCompletion"/> state. The awaiting code is executed
 /// asynchronously so it won't block the caller of this method.
 /// </summary>
 /// <typeparam name="T">The type of the result.</typeparam>
 /// <param name="tcs"></param>
 /// <param name="result">The result value to bind to this <see cref="Task"/>.</param>
 /// <returns>True if the operation was successful; otherwise, false.</returns>
 public static bool TrySetResultAsync <T>(this TaskCompletionSource <T> tcs, T result)
 {
     return(FakeSynchronizationContext.Execute(() => tcs.TrySetResult(result)));
 }