DEV Community

Discussion on: How YOU can make your .NET programs more responsive with async/await in .NET Core, C# and VS Code

Collapse
 
tyrrrz profile image
Oleksii Holub • Edited

await Task.FromResult that's a good one 😂
You're confusing Task.Run with Task.Result. The latter doesn't do any calculations, it just returns a completed task that you don't need to await. In fact, awaiting it just creates an unnecessary state machine that can hurt throughput.

Collapse
 
softchris profile image
Chris Noring

Well the Task result is immediately known, i.e 1+2, which is what I 'm using it for docs.microsoft.com/en-us/dotnet/ap.... Is it the best use of it? Probably not. Could I have been using Task.Run? Probably. The whole point of that method is generally to showcase the async/await combination. I think you are reading too much into a first sample method Alexey. I was making an analogy to Promise.resolve in the JavaScript world...

Collapse
 
tyrrrz profile image
Oleksii Holub

The point here was that using await with Task.FromResult is unnecessary and counterproductive.

Thread Thread
 
softchris profile image
Chris Noring

That I agree with.. I was showcasing async/await .. I will update the text to talk about the difference of Task.Run and Task.FromResult