Question

With Iterators, the following generic delegate is possible:

public delegate IEnumerable<TOut> MyDelegate<TIn>(TIn param1);

With the new async/await in C# 5.0 CTP, I expect to be able to create the analogous delegate as follows:

public delegate async TOut MyDelegate<TIn>(TIn param1);

I can't find the C# 5.0 spec or any help in this regard. Anyone know how this can be written or if it can't be written and why?

Thanks!

Was it helpful?

Solution

async is an implementation detail, not an interface specification. An async delegate doesn't make sense.

Any method that returns an "awaitable" (such as Task or Task<T>) can be used with await.

So an "asynchronous delegate" would be any delegate type that returns Task or Task<T> (or any other kind of awaitable). In your case:

public delegate Task<TOut> MyDelegate<TIn, TOut>(TIn param1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top