I'm new to async function, just want to ask why we need TaskAwaiter, when it is just a wrapper of Task, below is some source code
public struct TaskAwaiter<TResult> : ICriticalNotifyCompletion, INotifyCompletion {
private readonly Task<TResult> m_task;
internal TaskAwaiter(Task<TResult> task) {
m_task = task;
}
public bool IsCompleted {
get { return m_task.IsCompleted; }
}
public TResult GetResult();
public void OnCompleted(Action continuation);
//...
}
We know that when we await a task such as await task;, the compiler calls the task object's GetAwaiter method, then the a couple of complicated things kicks in, such as state machine, AsyncTaskMethodBuilder etc. But every operation on TaskAwaiter is actually an operation on m_task, so why not just use Task to replace TaskAwaiter?