public override async Task ProcessAsync(ILiaraContext context) { if (context.Request.Info.Path.StartsWith("/parallel")) { // Run all three handlers in parallel. var t1 = new ParallelHandler1().ProcessAsync(context); var t2 = new ParallelHandler2().ProcessAsync(context); var t3 = new ParallelHandler3().ProcessAsync(context); // Optionally, continue with other handlers in chain. // or add the next line to the end of the function to do that only when the parallel process is complete. // base.ProcessAsync(content); // When everything is complete, do these. // PS: It is async, doesn't block. await Task.WhenAll(new[] {t1, t2, t3}); // All parallel stuff done. Now, do something with results. // Note: It is by design that message handlers don't return values. Its just supposed to handle // the messages. Not report back. So, here, the parallel handlers are writing directly to the // stream. Or, the orderly result composition will take place here, which has been shown // on the next Handler. } else { await base.ProcessAsync(context); } }
public override async Task ProcessAsync(ILiaraContext context) { if (context.Request.Info.Path.StartsWith("/parallel")) { // Run all three handlers in parallel. var t1 = new ParallelHandler1().ProcessAsync(context); var t2 = new ParallelHandler2().ProcessAsync(context); var t3 = new ParallelHandler3().ProcessAsync(context); // Optionally, continue with other handlers in chain. // or add the next line to the end of the function to do that only when the parallel process is complete. // base.ProcessAsync(content); // When everything is complete, do these. // PS: It is async, doesn't block. await Task.WhenAll(new[] { t1, t2, t3 }); // All parallel stuff done. Now, do something with results. // Note: It is by design that message handlers don't return values. Its just supposed to handle // the messages. Not report back. So, here, the parallel handlers are writing directly to the // stream. Or, the orderly result composition will take place here, which has been shown // on the next Handler. } else { await base.ProcessAsync(context); } }