Example #1
0
 public static void RunTask(AsyncBehavior behavior, Action action)
 {
     RunTask(behavior, () =>
     {
         action();
         return(Task.FromResult(0));
     });
 }
Example #2
0
 protected void Receive <T>(AsyncBehavior behavior, Func <T, Task> handler)
 {
     EnsureMayConfigureMessageHandlers();
     _matchHandlerBuilders.Peek().Match <T>(m =>
     {
         Func <Task> wrap = () => handler(m);
         ActorTaskScheduler.RunTask(behavior, wrap);
     });
 }
Example #3
0
        public static void RunTask(AsyncBehavior behavior, Func <Task> action)
        {
            var context = ActorCell.Current;

            //if reentrancy is not allowed, suspend user message processing
            if (behavior == AsyncBehavior.Suspend)
            {
                context.SuspendReentrancy();
            }

            SetCurrentState(context.Self, context.Sender, null);

            //wrap our action inside a task, so that everything executing
            //directly or indirectly from the action is executed on our task scheduler

            Task.Factory.StartNew(async _ =>
            {
                //start executing our action and potential promise style
                //tasks
                await action()
                //we need to use ContinueWith so that any exception is
                //thrown inside the actor context.
                //this is needed for IO completion tasks that execute out of context
                .ContinueWith(
                    Rethrow,
                    Faulted,
                    TaskContinuationOptions.OnlyOnFaulted);

                //if reentrancy was suspended, make sure we re-enable message processing again
                if (behavior == AsyncBehavior.Suspend)
                {
                    context.ResumeReentrancy();
                }
            },
                                  Outer,
                                  CancellationToken.None,
                                  TaskCreationOptions.None,
                                  Instance);
        }
Example #4
0
 protected void RunTask(AsyncBehavior behavior, Func <Task> action)
 {
     ActorTaskScheduler.RunTask(behavior, action);
 }