Ejemplo n.º 1
0
 public static Func <Action <TResult>, Action <Exception>, IBackgroundTask> CreateForAsync <TResult>(FSharpAsync <TResult> async, DeviceDescriptionHolder dev)
 {
     return((onSuccess, onError) => {
         var disp = new MultipleAssignmentDisposable();
         var backgroundTask = new AnonymousBackgroundTask();
         backgroundTask.name = "Restore device " + dev.Name;
         backgroundTask.description = "Address: " + dev.Address;
         backgroundTask.state = BackgroundTaskState.InProgress;
         backgroundTask.disposable = Disposable.Create(() => {
             disp.Dispose();
             backgroundTask.state = BackgroundTaskState.Canceled;
         });
         disp.Disposable = async.Subscribe(
             res => {
             onSuccess(res);
             backgroundTask.state = BackgroundTaskState.Completed;
         },
             err => {
             onError(err);
             backgroundTask.state = BackgroundTaskState.Failed;
         }
             );
         return backgroundTask;
     });
 }
 public static Func <Action <TResult>, Action <Exception>, IBackgroundTask> CreateForAsync <TResult>(FSharpAsync <TResult> async)
 {
     return((onSuccess, onError) => {
         var disp = new MultipleAssignmentDisposable();
         var backgroundTask = new AnonymousBackgroundTask();
         backgroundTask.name = "upgarde firmware";
         backgroundTask.state = BackgroundTaskState.InProgress;
         backgroundTask.disposable = Disposable.Create(() => {
             disp.Dispose();
             backgroundTask.state = BackgroundTaskState.Canceled;
         });
         disp.Disposable = async.Subscribe(
             res => {
             onSuccess(res);
             backgroundTask.state = BackgroundTaskState.Completed;
         },
             err => {
             onError(err);
             backgroundTask.state = BackgroundTaskState.Failed;
         }
             );
         return backgroundTask;
     });
 }