Esempio n. 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();
        }
Esempio n. 2
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();
        }