I have a class (simplified sample and only the relevant parts are shown)
public class AsyncScenario : Task<Scenario> { public async AsyncScenario Test(Func<Task> action) { return await this; } }
I can not compile this because the return type of the method:
Compiler Error CS1983: "The return type of the async method must be invalid, Task or Task <T>"
Why is it not allowed for the async method to return a class derived from Task<T>?
Task<T>
# ? - , , † . .
, , async return, , ? , await this Scenario... # AsyncScenario ?
async
return
await this
Scenario
AsyncScenario
, , , - . , , , , , , , , , , return.
, , , , .
† , : async ?, Lucian Wischik, VB.NET( #). . Jon Skeet answer at .
, GetAwaiter :
public static async Task<Scenario> Test() { return await new AsyncScenario(); } public class AsyncScenario { public TaskAwaiter<Scenario> GetAwaiter() { return new TaskAwaiter<Scenario>(); } }