Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading.Tasks;
- namespace RxVsTplSample
- {
- public class TplAsyncOperation<TArg, TResult>
- {
- Func<TArg, Task<TResult>> operation;
- public TplAsyncOperation(Func<TArg, Task<TResult>> operation)
- {
- this.operation = operation;
- }
- public IAsyncResult BeginInvoke(TArg arg, AsyncCallback callback, object state)
- {
- var task = operation(arg);
- task.ContinueWith(_ => callback(task));
- return task;
- }
- public TResult EndInvoke(IAsyncResult result)
- {
- return ((Task<TResult>)result).Result;
- }
- }
- }
Add Comment
Please, Sign In to add comment