Exemplo n.º 1
0
        private async Task StartCoreAsync()
        {
            try
            {
                _log.Trace("Starting");
                _stopCancellation.Token.ThrowIfCancellationRequested();
                var processTask = await TaskRunner
                                  .RunInBackground(
                    () => StartProcessAsync(_stopCancellation.Token),
                    _stopCancellation.Token)
                                  .ConfigureAwait(false);

                processTask.ContinueWithSynchronously((Action <Task>)OnProcessCompleted).IgnoreAwait(_log);
                _startCompletion.TryComplete();
            }
            catch (OperationCanceledException) when(_stopCancellation.IsCancellationRequested)
            {
                _log.Trace("Start canceled");
                _startCompletion.TryComplete();
                _completion.TryComplete();
            }
            catch (Exception ex)
            {
                _log.Trace("Start failed: {0}", ex.FormatTypeAndMessage());
                _startCompletion.TryFail(ex);
                _completion.TryFail(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        public void NoUnobservedTaskExceptionsAfterCompletionLogged()
        {
            var promise = new Promise();

            promise.Task.LogCompletion(LogManager.GetLogger <PromiseTests>());
            promise.TryFail(new Exception("NoUnobservedTaskExceptionsAfterCompletionLogged!"));
        }
Exemplo n.º 3
0
 private static void PropagateCompletedTaskToPromise <T>(Task <T> task, Promise <T> promise)
 {
     if (task.IsCanceled)
     {
         promise.TryCancel();
     }
     else if (task.IsFaulted)
     {
         promise.TryFail(task.Exception.InnerExceptions);
     }
     else
     {
         promise.TryComplete(task.Result);
     }
 }
Exemplo n.º 4
0
 public bool TryFail(Exception error) => _inner.TryFail(error);
Exemplo n.º 5
0
        public void NoUnobservedExceptionsOnGenericPromise()
        {
            var promise = new Promise <bool>();

            promise.TryFail(new Exception("NoUnobservedExceptionsOnGenericPromise!"));
        }