I\'m looking for best practice around calling multiple async methods where each next method relies on the values returned from one before.
I\'m experimenting with 2
I'm looking for best practice around calling multiple async methods where each next method relies on the values returned from one before.
A lot of asynchronous questions can be answered by looking at the synchronous equivalent. If all the methods are synchronous and each method depends on the results of previous methods, how would that look?
var T1 = Sum(2,5);
var T2 = Sum(T1, 7);
var T3 = Sum(T2, 7);
Then the asynchronous equivalent would be:
var T1 = await SumAsync(2,5);
var T2 = await SumAsync(T1, 7);
var T3 = await SumAsync(T2, 7);
P.S. For future reference, do not insert StartNew
or Task.Run
as generic placeholders for asynchronous code; they just confuse the issue since they have very specific use cases. Use await Task.Delay
instead; it's the Thread.Sleep
of the async world.