Пример #1
0
        public IAsync Enqueue(QueueSide qSide, Action callback)
        {
            Validate.Begin().IsNotNull <Action>(callback, "callback").IsTrue(((qSide == QueueSide.Front) || (qSide == QueueSide.Back)), "qSide is not a valid member of the QueueSide enumeration").Check();
            IAsyncSource source = Async.NewSource();

            if (this.pleaseAbort)
            {
                source.Throw(new OperationCanceledException("The work queue has shut down."));
            }
            else
            {
                object sync = this.Sync;
                lock (sync)
                {
                    Action item = delegate {
                        callback.Try().Into(source);
                    };
                    Action action2 = delegate {
                        source.Throw(new OperationCanceledException("The dispatcher has shut down."));
                    };
                    if (qSide == QueueSide.Front)
                    {
                        this.runFnQ.EnqueueFront(item);
                        this.cancelFnQ.EnqueueFront(action2);
                    }
                    else
                    {
                        this.runFnQ.Enqueue(item);
                        this.cancelFnQ.Enqueue(action2);
                    }
                    ThreadPool.QueueUserWorkItem(this.threadPoolCallback);
                }
            }
            return(source.AsReceiveOnly());
        }
        public static IAsync <T> BeginEval <T>(this IAsyncWorkQueue queue, Func <T> f)
        {
            IAsyncSource <T> source = Async.NewSource <T>();

            queue.BeginTry(delegate {
                try
                {
                    Result <T> result = f.Eval <T>();
                    source.SetResult(result);
                }
                catch (Exception exception)
                {
                    source.Throw <T>(new TargetInvocationException(exception));
                }
            });
            return(source.AsReceiveOnly <T>());
        }
Пример #3
0
 public static bool ErrorInto <T, U>(this Result <T> tResult, IAsyncSource <U> source) =>
 (tResult.IsError && source.Throw <U>(tResult.Error));