ValueTask for synchronous method
10:54 02 Feb 2021

I am implementing a simple lookup service using concurrent dictionary to store data. Since most of the methods using this service will be async I am considering exposing the lookup functions with ValueTask.

Pseudocode:

public ValueTask GetResultAsync(string key)
{
    return ValueTask.FromResult(_dictionary.FirstOrDefault(p => p.Key == key).Value);
}

Does this approach make sense and is there any caveats ?

c# asynchronous task valuetask