Monday, June 22, 2015

Wrapping IAsyncResult in Task<> using FromAsync

I'm working with a webservice for which a proxy has been generated with the APM pattern for asynchronous calls. I didn't know this acronym, it stands for Asynchronous Programming Model ( see this blog post ) and the one with Async/Await ( and thus with tasks ) is called TAP for Task-based Asynchronous Pattern.

Anyway - I just wanted to async/await these calls and as it turns out it's super easy. Here's the method signature before:


Wrap them using Task.Factory.FromAsync:


... and you're done. Super easy - unit tests verify that it works like a charm.

Credits to Justin Lovell who helped me get started and Stephen Cleary for another great blog post.

No comments:

Post a Comment