You are right that profitability and expectation are closely related. Both are points in the workflow where the current method is paused, control returns to the caller, and the method resumes at an undefined point in the future at the point where the exit / wait occurred.
But they differ from each other in terms of their effect on their operands. They are actually doubles of each other. The output gives a new meaning when a code that iterates a sequence is required. Waiting retrieves a value when it is created by an asynchronously executed task.
Null is an absolutely acceptable value, so it makes sense to get income to its caller. But null is not a valid task, so it makes no sense to expect you to extract the value from the task.
Currently in Unity3d you can return return null; inside the coroutine to represent "Wait for the next frame."
In an asynchronous workflow with asynchronous wait, the counterpart is yield return null; is only return null; . This means that "complete this part of the asynchronous workflow by providing a null reference." Why are you not just returning null if you are going to create a task whose result is null?
Let me say one more way that may be clearer. Obviously this doesn't make sense:
foreach(var x in null) Console.WriteLine(x);
This is identically pointless:
var x = await null; Console.WriteLine(x);
This is the same logical. Foreach means “retrieve a value from a sequence until values are available,” but null is not a sequence. Similarly, “wait” means “extract a value from a task as soon as a value is available”, but null is not a task.
What is the key: the asynchronous analogue of await not yield return , it is foreach . This is the mechanism that extracts T from IEnumerable<T> or Task<T> . What puts T in the monadic type is yield return for IEnumerable<T> and return for Task<T> .
Eric Lippert
source share