Reputation: 29159
TaskTupleAwaiter
https://github.com/buvinghausen/TaskTupleAwaiter allows us to do
// For example
// Task<int> t1() { return Task.FromResult(1); }
// Task<string> t2() { return Task.FromResult("a"); }
var (r1, r2) = await (t1(), t2());
How does it compare to the following code? (Besides more concise code)
var t1task = t1();
var t2task = t2();
// var r1 = await t1task; // Edited one is actually I wanted to ask
// var r2 = await t2task;
await Task.WhenAll(t1task, t2task);
var r1 = t1task.Result;
var r2 = t2task.Result;
The project hasn't had any update for a while. I'm wondering if I need to remove it from our repo.
Upvotes: 1
Views: 205
Reputation: 141730
Based on the source code await (t1(), t2())
should be the same as:
var t1task = t1();
var t2task = t2();
await Task.WhenAll(t1task, t2task);
var r1 = t1task.Result;
var r2 = t2task.Result;
Which should be preferable compared to the original code (now commented out) in the question.
The project hasn't had any update for a while.
The source code was updated only 5 month ago, project targets latest released (at the moment of writing) version of .NET - .NET 6. I would say that for smaller projects which does not have a lot of features such maintainability schedule should be just fine, so personally I see no major reason to switch.
Upvotes: 2