Exemple #1
0
        Task <T> Execute(Task <T> task, Func <T, Task <T> > continuationTask, ExecuteOptions options)
        {
            if (task.IsCompleted && options.HasFlag(ExecuteOptions.RunSynchronously))
            {
                if (task.IsFaulted)
                {
                    return(TaskUtil.Faulted <T>(task.Exception.InnerExceptions));
                }

                if (task.IsCanceled || _cancellationToken.IsCancellationRequested)
                {
                    return(TaskUtil.Canceled <T>());
                }

                if (task.Status == TaskStatus.RanToCompletion)
                {
                    try
                    {
                        return(continuationTask(task.Result));
                    }
                    catch (Exception ex)
                    {
                        return(TaskUtil.Faulted <T>(ex));
                    }
                }
            }

            return(ExecuteAsync(task, continuationTask, options));
        }
Exemple #2
0
        public TaskComposer(T payload, CancellationToken cancellationToken = default(CancellationToken))
        {
            _payload           = payload;
            _cancellationToken = cancellationToken;

            _task = cancellationToken.IsCancellationRequested
                ? TaskUtil.Canceled <T>()
                : TaskUtil.Completed(payload);
        }