Play TaskCompletionSource<TResult>

The Discussion

  • User profile image

    Very nice, thank you

  • User profile image

    Perhaps I need to do more research on the new Task APIs, but I didn't quite understand why we would use a TaskCompletionSource<T> instead of using the EAP functionality directly.  Is it because the Task APIs give us better tooling/functionality than EAP?

  • User profile image

    Hi cgillum-


    This was just an example Danny was providing on how TCS<T> could be used to represent any asynchronous operation, including EAP implementations.  However, the compositionality provided by Task<T> now allows you to start doing some really useful things.   For example, if you wanted to download a bunch of web pages asynchronously and then only do something when all of them were complete, with WebClient by itself you'd have to code up that logic manually; in contrast, if you had a Task<T> for each download, you could then use ContinueWhenAll to launch additional work when all of those downloads completed (and you'd get back a Task that represents that continuation).  In short, once you have a Task<T> to represent the EAP operation, you can compose it with any other tasks you might have, and you have the full functionality afforded to tasks to process that EAP operation.


Add Your 2 Cents