internal static Task RunOrQueueTask(this OrleansTaskScheduler scheduler, Func <Task> taskFunc, IGrainContext targetContext) { var currentContext = RuntimeContext.CurrentGrainContext; if (currentContext is object && currentContext.Equals(targetContext)) { try { return(taskFunc()); } catch (Exception exc) { return(Task.FromResult(exc)); } } return(scheduler.QueueTask(taskFunc, targetContext)); }
internal static Task RunOrQueueTask(this OrleansTaskScheduler scheduler, Func <Task> taskFunc, ISchedulingContext targetContext) { var currentContext = RuntimeContext.CurrentActivationContext; if (SchedulingUtils.IsAddressableContext(currentContext) && currentContext.Equals(targetContext)) { try { return(taskFunc()); } catch (Exception exc) { return(Task.FromResult(exc)); } } return(scheduler.QueueTask(taskFunc, targetContext)); }
internal static Task <T> RunOrQueueTask <T>(this OrleansTaskScheduler scheduler, Func <Task <T> > taskFunc, IGrainContext targetContext) { var currentContext = RuntimeContext.CurrentGrainContext; if (currentContext is object && currentContext.Equals(targetContext)) { try { return(taskFunc()); } catch (Exception exc) { var resolver = new TaskCompletionSource <T>(TaskCreationOptions.RunContinuationsAsynchronously); resolver.TrySetException(exc); return(resolver.Task); } } return(scheduler.QueueTask(taskFunc, targetContext)); }
internal static Task <T> RunOrQueueTask <T>(this OrleansTaskScheduler scheduler, Func <Task <T> > taskFunc, ISchedulingContext targetContext) { ISchedulingContext currentContext = RuntimeContext.CurrentActivationContext; if (SchedulingUtils.IsAddressableContext(currentContext) && currentContext.Equals(targetContext)) { try { return(taskFunc()); } catch (Exception exc) { var resolver = new TaskCompletionSource <T>(); resolver.TrySetException(exc); return(resolver.Task); } } return(scheduler.QueueTask(taskFunc, targetContext)); }