コード例 #1
0
        public static Task UnwrapActor(this Task <Task> task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            return(runtime.StartNew <object>(() =>
            {
                runtime.WaitForActor(task, false);
                switch (task.Status)
                {
                case TaskStatus.Canceled:
                    runtime.CancelSelf();
                    break;

                case TaskStatus.Faulted:
                    throw new AggregateException();

                case TaskStatus.RanToCompletion:
                    var res = task.Result /*OK*/;
                    if (res == null)
                    {
                        runtime.CancelSelf();
                    }
                    else
                    {
                        runtime.WaitForActor(res, false);

                        switch (res.Status)
                        {
                        case TaskStatus.Canceled:
                            runtime.CancelSelf();
                            break;

                        case TaskStatus.Faulted:
                            throw new AggregateException();

                        case TaskStatus.RanToCompletion:
                            return null;
                        }
                    }
                    break;

                default:
                    runtime.InternalError();
                    break;
                }
                throw new InvalidOperationException();
            }));
        }