示例#1
0
        public IAsync Receive(Action <Result> handler)
        {
            IAsyncSource source = Async.NewSource();
            bool         flag   = false;
            object       sync   = this.sync;

            lock (sync)
            {
                if (this.result != null)
                {
                    flag = true;
                }
                else
                {
                    if (this.handlers == null)
                    {
                        this.handlers = new List <Tuple <Action <Result>, IAsyncSource> >(1);
                    }
                    this.handlers.Add(Tuple.Create <Action <Result>, IAsyncSource>(handler, source));
                }
            }
            if (flag)
            {
                Result result = handler.Try <Result>(this.result);
                source.SetResult(result);
            }
            return(source.AsReceiveOnly());
        }
示例#2
0
        public IAsync BeginTry(Action callback)
        {
            IAsyncSource source = Async.NewSource();

            this.dispatcher.BeginInvoke(delegate {
                try
                {
                    Result @void = Result.Void;
                    callback();
                    source.SetResult(@void);
                }
                catch (Exception exception1)
                {
                    Result result = Result.NewError(exception1);
                    source.SetResult(result);
                }
            }, Array.Empty <object>());
            return(source.AsReceiveOnly());
        }
        public IAsync BeginTry(Action callback)
        {
            base.VerifyAccess();
            IAsyncSource async = Async.NewSource();

            this.syncContext.Post(delegate(object _) {
                async.SetResult(callback.Try());
            });
            return(async);
        }
        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>());
        }
示例#5
0
 public static bool Into <T>(this Result <T> result, IAsyncSource <T> async) =>
 async.SetResult(result);
示例#6
0
 public static bool Into(this Result result, IAsyncSource async) =>
 async.SetResult(result);
 public static bool Throw <T>(this IAsyncSource <T> source, Exception ex) =>
 source.SetResult(Result.NewError <T>(ex));
 public static bool Return <T>(this IAsyncSource <T> source, T value) =>
 source.SetResult(Result.New <T>(value));
 public static bool Return(this IAsyncSource source) =>
 source.SetResult(Result.Void);