public Java.Lang.Object AttachCompleter(CallbackToFutureAdapter.Completer completer) { var jobName = this.InputData.GetString(ShinyJobIdentifier); if (jobName.IsEmpty()) { completer.Set(Result.InvokeFailure()); } else { ShinyHost .Resolve <IJobManager>() .Run(jobName, this.cancelSource.Token) .ContinueWith(x => { switch (x.Status) { case TaskStatus.Canceled: completer.SetCancelled(); break; case TaskStatus.Faulted: Log.Write(x.Exception); completer.SetException(new Java.Lang.Throwable(x.Exception.ToString())); break; case TaskStatus.RanToCompletion: completer.Set(Result.InvokeSuccess()); break; } }); } return("AsyncOp"); }
Object CallbackToFutureAdapter.IResolver.AttachCompleter(CallbackToFutureAdapter.Completer p0) { try { var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task.Run(async() => { Log.Debug("Starting Worker {Name}", GetType().FullName); return(await DoWorkAsync(_cts.Token)); }, _cts.Token) .ContinueWith(previous => { if (previous.IsCompletedSuccessfully) { Log.Trace(previous.Exception, "Worker {Name} completed successfully", GetType().FullName); p0.Set(Result.InvokeSuccess(previous.Result)); } else { if (previous.IsCanceled) { Log.Trace(previous.Exception, "Worker {Name} was cancelled", GetType().FullName); p0.SetCancelled(); } if (previous.IsFaulted) { Log.Error(previous.Exception, "Worker {Name} raised an exception", GetType().FullName); p0.SetException(new Error(previous.Exception?.ToString() ?? "Unknown cause")); } } }, _cts.Token, TaskContinuationOptions.None, scheduler); } catch (Exception e) { Log.Error(e, "Worker {Name} raised an exception", GetType().FullName); } return(GetCompletionTag() as Object); }
public Java.Lang.Object AttachCompleter(CallbackToFutureAdapter.Completer completer) { var jobName = this.InputData.GetString(ShinyJobIdentifier); var jobManager = ShinyHost.Resolve <IJobManager>(); //if (jobManager != null && !jobName.IsEmpty()) if (jobName.IsEmpty() || jobManager == null) { //completer.Set(Result.InvokeFailure()); completer.Set(Result.InvokeSuccess()); } else { jobManager .Run(jobName, this.cancelSource.Token) .ContinueWith(x => { switch (x.Status) { case TaskStatus.Canceled: completer.SetCancelled(); break; case TaskStatus.Faulted: ShinyHost .LoggerFactory .CreateLogger <ILogger <IJobManager> >() .LogError(x.Exception, "Error in job"); completer.SetException(new Java.Lang.Throwable(x.Exception.ToString())); break; case TaskStatus.RanToCompletion: completer.Set(Result.InvokeSuccess()); break; } }); } return("AsyncOp"); }