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; } }
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); } }
public bool TryComplete() => _inner.TryComplete(Nothing.Instance);