I don\'t know if I am thinking in the wrong way about TPL, but I have difficulty understanding how to obtain the following:
I have two functions
Task<
If you are unable to use await
, you can certainly use Unwrap
, but it handles exceptions sub-optimally. The method I prefer is Then
as described in this article. Composition becomes simple and elegant:
Task Combined()
{
return getA().Then(getB);
}
For those interested in the details, I wrote a blog post a while ago about exactly this problem of composing asynchronous methods, and how monads provide an elegant solution.