Пример #1
0
 public void SetException_OperationCanceledException_CancelsTask()
 {
     AsyncValueTaskMethodBuilder<int> b = ValueTask<int>.CreateAsyncMethodBuilder();
     var e = new OperationCanceledException();
     ValueTask<int> vt = b.Task;
     b.SetException(e);
     Assert.True(vt.IsCanceled);
     Assert.Same(e, Assert.Throws<OperationCanceledException>(() => vt.GetAwaiter().GetResult()));
 }
Пример #2
0
 public void SetException_AfterAccessTask_FaultsTask()
 {
     AsyncValueTaskMethodBuilder<int> b = ValueTask<int>.CreateAsyncMethodBuilder();
     var e = new FormatException();
     ValueTask<int> vt = b.Task;
     b.SetException(e);
     Assert.True(vt.IsFaulted);
     Assert.Same(e, Assert.Throws<FormatException>(() => vt.GetAwaiter().GetResult()));
 }
            private void MoveNext()
            {
                int          num = __1__state;
                NullCoalesce c   = __4__this;
                int          result;

                try
                {
                    /* M1AsyncAsyncA__d__5
                     * ValueTaskAwaiter<int> awaiter;
                     * if (num != 0)
                     * {
                     *  ValueTask<int> valueTask = (c.FAsync != null) ? c.FAsync() : default(ValueTask<int>);
                     *  awaiter = valueTask.GetAwaiter();
                     *  if (!awaiter.IsCompleted)
                     *  {
                     *      num = (__1__state = 0);
                     *      __u__1 = awaiter;
                     *      __t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                     *      return;
                     *  }
                     * }
                     * else
                     * {
                     *  awaiter = __u__1;
                     *  __u__1 = default(ValueTaskAwaiter<int>);
                     *  num = (__1__state = -1);
                     * }
                     * result = awaiter.GetResult();
                     */

                    /* M1AsyncAsyncB__d__6 */

                    int num2;
                    ValueTaskAwaiter <int> awaiter;
                    if (num != 0)
                    {
                        if (c.FAsync == null)
                        {
                            num2 = 0;
                            goto IL_0082;
                        }
                        awaiter = c.FAsync().GetAwaiter();
                        if (!awaiter.IsCompleted)
                        {
                            num    = (__1__state = 0);
                            __u__1 = awaiter;
                            __t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                            return;
                        }
                    }
                    else
                    {
                        awaiter = __u__1;
                        __u__1  = default(ValueTaskAwaiter <int>);
                        num     = (__1__state = -1);
                    }
                    num2 = awaiter.GetResult();
                    goto IL_0082;
IL_0082:
                    result = num2;
                    /**/

                    /* M2AsyncAsync__d__8
                     *
                     * ValueTaskAwaiter<int> awaiter;
                     * if (num != 0)
                     * {
                     *  Func<ValueTask<int>> fAsync = c.FAsync;
                     *  ValueTask<int> valueTask = (fAsync != null) ? fAsync() : default(ValueTask<int>);
                     *  awaiter = valueTask.GetAwaiter();
                     *  if (!awaiter.IsCompleted)
                     *  {
                     *      num = (__1__state = 0);
                     *      __u__1 = awaiter;
                     *      __t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                     *      return;
                     *  }
                     * }
                     * else
                     * {
                     *  awaiter = __u__1;
                     *  __u__1 = default(ValueTaskAwaiter<int>);
                     *  num = (__1__state = -1);
                     * }
                     * result = awaiter.GetResult();
                     */

                    // ----
                }
                catch (Exception exception)
                {
                    __1__state = -2;
                    __t__builder.SetException(exception);
                    return;
                }
                __1__state = -2;
                __t__builder.SetResult(result);
            }