What will happen? LongRunningTaskThatSetsFoo
isn't allowed to return the Task
until it has set foo
, meaning it has to provide foo
when starting the asynchronous operation, and not when the asynchronous operation ends. This probably just doesn't make sense. I suppose technically you could include information about what LongRunningTaskThatSetsFoo
is going to do, rather than what it has done, but I'm...skeptical.
Anyway, since foo
has to have been set before the asyncrhonous operation would be allowed to start (which is when LongRunningTaskThatSetsFoo
returns) UseFooToDoSomething
will then use foo
, then the method will return and execution will continue after the Task
returned by LongRunningTaskThatSetsFoo
completes.
You almost certainly don't want to do this. If LongRunningTaskThatSetsFoo
produces a value, then it should return a Task<T>
where foo
is the result of that Task<T>
. Of course, asynchronous operations that produce a result aren't in any way useless. They're quite useful. The current thread wouldn't be able to do any work that depended on the result, but they'd be able to perform operations that didn't depend on the result, and let the operations that did depend on the result start running as soon as the result is computed.