Beispiel #1
0
 void async_call()
 {
     RpcPromise p = new RpcPromise();
     p.then(_ => {
         prx.echo_async("this is a sync text",
             delegate(string result, RpcAsyncContext ctx) {
                 Console.WriteLine("echo() result:" + result);
                 ctx.promise.data = result;
                 ctx.onNext();
                 //ctx.again();
             }, _.promise);
     }).then(_ => {
         prx.timeout_async(1, delegate(RpcAsyncContext ctx) {
             Console.WriteLine("timeout completed!");
             ctx.onNext();
         },_.promise);
     });
     RpcPromise pe = p.error(_ => {
         Console.WriteLine("async call error:"+ _.exception.ToString());
         _.onNext();
     });
     p.final(_ => {
         Console.WriteLine(" commands be executed completed!");
     });
     p.end();
 }
Beispiel #2
0
        /**
         * onNext()
         * promise下一个处理
         * 同一个promise中 step1 -> step2
         * 下一个promise 跳转到上级 promise
         */
        public void onNext(RpcAsyncContext ctx, RpcPromise from = null)
        {
            if (true)
            {
                if (from != null && from._lastPoint != null)
                {
                    int index = _sucesslist.IndexOf(from._lastPoint);
                    _sucesslist.RemoveRange(0, index + 1);
                }

                if (_sucesslist.Count == 0)
                {
                    onFinally(ctx);
                    return;
                }
                OnNext next = null;
                next = _sucesslist[0];
                _sucesslist.RemoveAt(0);
                _currentNext = next;
                if (next != null)
                {
                    next(ctx);
                }
            }
        }
Beispiel #3
0
        public void join(RpcPromise promise)
        {
            promise._nextPromise = this; //
            OnNext last = null;

            if (_sucesslist.Count != 0)
            {
                last = _sucesslist[_sucesslist.Count - 1];
            }
            promise._lastPoint = last;
        }
Beispiel #4
0
        /**
         *  at here  , new promise be created as Error processing fork.
         *  you can promise.wait util the error-routine return.
         */
        public RpcPromise error(OnNext error)
        {
            RpcPromise promise = new RpcPromise();

            if (true)
            {
                OnNext succ = null;

                if (_sucesslist.Count != 0)
                {
                    succ = _sucesslist[_sucesslist.Count - 1]; // select last OnNext
                }

                KeyValuePair <RpcPromise, OnNext> kv = new KeyValuePair <RpcPromise, OnNext>(promise, succ);
                _errorlist.Add(kv);
                promise._nextPromise = this;
                promise.then(error);
            }
            return(promise);
        }
Beispiel #5
0
        public void onError(RpcAsyncContext ctx)
        {
            if (_errorlist.Count == 0)
            {
                onFinally(ctx);
                return;
            }
            // pick out one fork-promise
            KeyValuePair <RpcPromise, OnNext> kv = _errorlist[0];
            OnNext     succ = kv.Value;
            RpcPromise next = kv.Key;

            _errorlist.RemoveAt(0);
            // scan list and remove all nodes which's depth of node is less than promise.
            int index = _sucesslist.IndexOf(succ);

            _sucesslist.RemoveRange(0, index + 1);

            if (next != null)
            {
                ctx.promise = next;
                next.onNext(ctx);
            }
        }
Beispiel #6
0
        void test_promise()
        {
            RpcPromise p = new RpcPromise();
            p.then(delegate(RpcAsyncContext ctx) {
                ctx.promise.data = "abc";
                Console.WriteLine("step 1.1");
                ctx.promise.onNext(ctx);
            }).then(delegate(RpcAsyncContext ctx) {
                Console.WriteLine("step 1.2");
                Console.WriteLine(ctx.promise.data);
                //ctx.promise.onNext(ctx);
                ctx.promise.onError(ctx);
            });
            RpcPromise p2 = p.error(delegate(RpcAsyncContext ctx) {
                //p.onNext(ctx,ctx.promise);
                Console.WriteLine("step 2.1");
                ctx.promise.onError(ctx);
            });
            RpcPromise p3 = p2.error(delegate(RpcAsyncContext ctx) {
                Console.WriteLine("step 3.1");
                ctx.promise.onNext(ctx);
            });
            p3.then(delegate(RpcAsyncContext ctx) {
                Console.WriteLine("step 2.2");
                ctx.promise.onNext(ctx);
            });

            p.then(delegate(RpcAsyncContext ctx) {
                Console.WriteLine("step 1.3");
                ctx.promise.onNext(ctx);
            }).final(delegate(RpcAsyncContext ctx) {
                Console.WriteLine("final.");
                Console.WriteLine(ctx.promise.data);
                Console.ReadKey(true);
            }).end();
        }
Beispiel #7
0
 public RpcAsyncContext( object cookie,RpcPromise promise) {
     this.cookie = cookie;
     this.promise = promise;
 }
Beispiel #8
0
        /**
         *  at here  , new promise be created as Error processing fork.
         *  you can promise.wait util the error-routine return.
         */
        public RpcPromise error(OnNext error )
        {
            RpcPromise promise = new RpcPromise();
            if(true) {
                OnNext succ = null;

                if (_sucesslist.Count != 0) {
                    succ = _sucesslist[_sucesslist.Count - 1]; // select last OnNext
                }

                KeyValuePair<RpcPromise,OnNext> kv = new KeyValuePair<RpcPromise, OnNext>(promise,succ);
                _errorlist.Add( kv );
                promise._nextPromise = this;
                promise.then(error);
            }
            return promise;
        }
Beispiel #9
0
        /**
         * onNext()
         * promise下一个处理
         * 同一个promise中 step1 -> step2
         * 下一个promise 跳转到上级 promise
         */
        public void onNext(RpcAsyncContext ctx,RpcPromise from = null)
        {
            if (true) {
                if (from != null && from._lastPoint != null)
                {
                    int index = _sucesslist.IndexOf(from._lastPoint);
                    _sucesslist.RemoveRange(0,index+1);
                }

                if (_sucesslist.Count == 0) {
                    onFinally(ctx);
                    return;
                }
                OnNext next = null;
                next = _sucesslist[0];
                _sucesslist.RemoveAt(0);
                _currentNext = next;
                if ( next != null) {
                    next( ctx );
                }
            }
        }
Beispiel #10
0
 public void join(RpcPromise promise)
 {
     promise._nextPromise = this; //
     OnNext last = null;
     if (_sucesslist.Count != 0) {
         last = _sucesslist[_sucesslist.Count - 1];
     }
     promise._lastPoint = last;
 }
Beispiel #11
0
 public RpcAsyncContext(object cookie, RpcPromise promise)
 {
     this.cookie  = cookie;
     this.promise = promise;
 }