Guest User

Untitled

a guest
Jul 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace RxVsTplSample
  5. {
  6. public class TplAsyncOperation<TArg, TResult>
  7. {
  8. Func<TArg, Task<TResult>> operation;
  9.  
  10. public TplAsyncOperation(Func<TArg, Task<TResult>> operation)
  11. {
  12. this.operation = operation;
  13. }
  14.  
  15. public IAsyncResult BeginInvoke(TArg arg, AsyncCallback callback, object state)
  16. {
  17. var task = operation(arg);
  18. task.ContinueWith(_ => callback(task));
  19. return task;
  20. }
  21.  
  22. public TResult EndInvoke(IAsyncResult result)
  23. {
  24. return ((Task<TResult>)result).Result;
  25. }
  26. }
  27. }
Add Comment
Please, Sign In to add comment