Basic usages and examples of C # Task.fromresult
This method is useful if you perform an asynchronous operation that returns a Task object, and the result of that task O Bject is already computed
There is common use cases I ' ve found:
- When you ' re implementing a interface that allows asynchronous callers, but your implementation is synchronous.
- When your ' re stubbing/mocking asynchronous code for testing
The above is generally used for unit testing;
Then there are also useful when we read the cache; Microsoft Official blog instance;
Https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-create-pre-computed-tasks
The thought above:
This method is useful if you perform an asynchronous operation that returns a Task object, and the result of that task O Bject is already computed.
has been calculated, or has been cached, the basic desired value;
Basic usages and examples of C # Task.fromresult