public async Task Invoke(IncomingContext context) { int currentIndex = 0; var semaphore = new SemaphoreSlim(1); Stack<Tuple<Task, TaskCompletionSource<ExceptionDispatchInfo>>> sources = new Stack<Tuple<Task, TaskCompletionSource<ExceptionDispatchInfo>>>(); while (currentIndex < executingElements.Count) { await semaphore.WaitAsync().ConfigureAwait(false); var element = executingElements[currentIndex]; currentIndex += 1; var tcs = new TaskCompletionSource<ExceptionDispatchInfo>(); var task = element.Invoke(context, () => { semaphore.Release(); return tcs.Task; }); sources.Push(Tuple.Create(task, tcs)); } ExceptionDispatchInfo exception = null; var anotherSemaphore = new SemaphoreSlim(1); var allTasks = new ConcurrentBag<Task>(); foreach (var source in sources) { await anotherSemaphore.WaitAsync().ConfigureAwait(false); if (exception != null) { context.Exceptions.Enqueue(exception); source.Item2.TrySetException(exception.SourceException); exception = null; } else { source.Item2.TrySetResult(null); } var task = source.Item1.ContinueWith(t => { if (t.Exception != null) { exception = ExceptionDispatchInfo.Capture(t.Exception.InnerException); } anotherSemaphore.Release(); }, TaskContinuationOptions.ExecuteSynchronously); allTasks.Add(task); } await Task.WhenAll(allTasks).ConfigureAwait(false); }
public async Task Invoke(IncomingContext context, Func <Task> next) { try { await next(); } catch (Exception e) { context.Exceptions.Dequeue().SourceException.StackTrace.Output(); } countdown.Signal(); }
public Task Invoke(IncomingContext context, Func<Task> next) { return next(); }
public async Task Invoke(IncomingContext context, Func<Task> next) { await Task.Delay(10).ConfigureAwait(false); throw new InvalidOperationException(nameof(ThrowException)); }
public async Task Invoke(IncomingContext context, Func<Task> next) { await Task.Delay(10).ConfigureAwait(false); await next().ConfigureAwait(false); }
static Task Connector(ChainFactory factory, TransportMessage message) { var pipeline = factory.Create(); var context = new IncomingContext(message); return pipeline.Invoke(context); }
public async Task Invoke(IncomingContext context, Func<Task> next) { try { await next(); } catch (Exception e) { context.Exceptions.Dequeue().SourceException.StackTrace.Output(); } countdown.Signal(); }
public async Task Invoke(IncomingContext context, Func<Task> next) { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await Task.Delay(10).ConfigureAwait(false); await next().ConfigureAwait(false); scope.Complete(); } }
public async Task Invoke(IncomingContext context, Func <Task> next) { await Task.Delay(10).ConfigureAwait(false); throw new InvalidOperationException(nameof(ThrowException)); }
public async Task Invoke(IncomingContext context, Func <Task> next) { await Task.Delay(10).ConfigureAwait(false); await next().ConfigureAwait(false); }
public Task Invoke(IncomingContext context, Func <Task> next) { return(next()); }