Awaitable expressions
The task of an await expression is required to be awaitable. An expression t is awaitable if one of the following holds: · t is of compile time type dynamic · t has an accessible instance or extension method called GetAwaiter with no parameters and no type parameters, and a return type A for which all of the following hold: o A implements the interface System.Runtime.CompilerServices.INotifyCompletion (hereafter known as INotifyCompletion for brevity) o A has an accessible, readable instance property IsCompleted of type bool o A has an accessible instance method GetResult with no parameters and no type parameters The purpose of the GetAwaiter method is to obtain an awaiter for the task. The type A is called the awaiter type for the await expression. The purpose of the IsCompleted property is to determine if the task is already complete. If so, there is no need to suspend evaluation. The purpose of the INotifyCompletion.OnCompleted method is to sign up a “continuation” to the task; i.e. a delegate (of type System.Action) that will be invoked once the task is complete. The purpose of the GetResult method is to obtain the outcome of the task once it is complete. This outcome may be successful completion, possibly with a result value, or it may be an exception which is thrown by the GetResult method.
|