Example #1
0
        public static ITask ExecuteToCompletion(DispatcherQueue dispatcherQueue, ITask task)
        {
            Port <EmptyValue> done = new Port <EmptyValue>();

            if (task.ArbiterCleanupHandler != null)
            {
                throw new InvalidOperationException(Resource1.TaskAlreadyHasFinalizer);
            }
            task.ArbiterCleanupHandler = delegate
            {
                done.Post(EmptyValue.SharedInstance);
            };
            dispatcherQueue.Enqueue(task);
            return(Arbiter.Receive <EmptyValue>(false, done, delegate(EmptyValue e)
            {
            }));
        }
Example #2
0
        public static Port <EmptyValue> WaitForMultipleTasks(DispatcherQueue taskQueue, params ITask[] tasks)
        {
            if (taskQueue == null)
            {
                throw new ArgumentNullException("taskQueue");
            }
            if (tasks == null)
            {
                throw new ArgumentNullException("tasks");
            }
            Port <EmptyValue> port = new Port <EmptyValue>();
            int num = 0;

            for (int i = 0; i < tasks.Length; i++)
            {
                ITask task = tasks[i];
                if (task != null)
                {
                    Arbiter.ExecuteToCompletion(taskQueue, task, port);
                    num++;
                }
            }
            Port <EmptyValue> donePort = new Port <EmptyValue>();

            if (num > 0)
            {
                ITask[] array = new ITask[1];
                array[0] = Arbiter.MultipleItemReceive <EmptyValue>(false, port, num, delegate(EmptyValue[] _)
                {
                    donePort.Post(EmptyValue.SharedInstance);
                });
                Arbiter.Activate(taskQueue, array);
            }
            else
            {
                donePort.Post(EmptyValue.SharedInstance);
            }
            return(donePort);
        }
Example #3
0
 public static MultipleItemGather MultipleItemReceive <T0, T1>(this PortSet <T0, T1> portSet, int totalItemCount, Handler <ICollection <T0>, ICollection <T1> > handler)
 {
     return(Arbiter.MultipleItemReceive <T0, T1>(portSet, totalItemCount, handler));
 }