Is there a way to use it (or something similar) for asynchronous methods that return a Task ?
Same as with any function returning a value: end the call in a helper method, returning void , "returning" the value via the ref parameter. Yes, this is clumsy, but in this way you are forced to write an initializer for the returned parameter, and this initializer is how it can be valid even if the call is deleted: you can never get uninitialized values.
[Conditional("DEBUG")] public void FooAsync(ref Task task) { Func<Task> impl = async () => {
Using:
public async Task CallFoo() { var task = Task.CompletedTask; FooAsync(ref task); await task; }
source share