当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript when.all函数代码示例

本文整理汇总了TypeScript中when.all函数的典型用法代码示例。如果您正苦于以下问题:TypeScript all函数的具体用法?TypeScript all怎么用?TypeScript all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了all函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

            function() {
                test.log("All registered.");

                var pl2 = [];

                pl2.push(session.call('com.myapp.longop', [3], {}, { receive_progress: true }).then(
                    function(res) {
                        test.log("Final:", res);
                    },
                    function(err) {
                        test.log("Error:", err);
                    },
                    function(progress) {
                        test.log("Progress:", progress);
                    }
                ));

                when.all(pl2).then(function() {
                    test.log("All finished.");
                    connection.close();

                    var chk = test.check()
                    assert(!chk, chk);
                    done();
                });
            },
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:26,代码来源:test_rpc_progress.ts

示例2: it

it('should connect with 10 clients and leave the session afterwards', function(done) {

    var test = new testutil.Testlog("test/test_connect.txt");
    var N = 10;

    test.log("connecting " + N + " sessions ...");

    var dl = testutil.connect_n(N);

    when.all(dl).then(
        function(sessions: Array<Session>) {
            test.log("all " + sessions.length + " sessions connected");

            for (var i = 0; i < sessions.length; ++i) {
                test.log("leaving session " + i);
                sessions[i].leave();
            }

            var chk = test.check();
            assert(chk === null, chk);
            done();
        },
        function(err) {
            test.log(err);
            assert(false, "Could not connect all clients");
            done();
        }
    );
});
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:29,代码来源:test_connect.ts

示例3: function

            function() {
                test.log("All registered.");

                var pl2 = [];

                pl2.push(session.call('com.math.slowsquare', [3]).then(
                    function(res) {
                        test.log("Slow Square:", res);
                    },
                    function(err) {
                        test.log("Error", err);
                    }
                ));

                pl2.push(session.call('com.math.square', [3]).then(
                    function(res) {
                        test.log("Quick Square:", res);
                    },
                    function(err) {
                        test.log("Error", err);
                    }
                ));

                when.all(pl2).then(function() {
                    test.log("All finished.");
                    connection.close();

                    var chk = test.check()
                    assert(!chk, chk);
                    done();
                });
            },
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:32,代码来源:test_rpc_slowsquare.ts

示例4: function

            function() {
                test.log("All registered.");

                function on_event(val) {
                    test.log("Someone requested to square non-positive:", val);
                }

                session.subscribe('com.myapp.square_on_nonpositive', on_event);

                var pl2 = [];

                var vals = [2, 0, -2];
                for (var i = 0; i < vals.length; ++i) {

                    pl2.push(session.call('com.myapp.square', [vals[i]], {}, { disclose_me: true }).then(
                        function(res) {
                            test.log("Squared", res);
                        },
                        function(error) {
                            test.log("Call failed:", error);
                        }
                    ));
                }

                when.all(pl2).then(function() {
                    test.log("All finished.");
                    connection.close();

                    var chk = test.check()
                    assert(!chk, chk);
                    done();
                });
            },
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:33,代码来源:test_rpc_options.ts

示例5: function

            function() {
                test.log("All registered.");

                var pl2 = [];

                var vals1 = [2, 0, -2];

                for (var i = 0; i < vals1.length; ++i) {

                    pl2.push(session.call('com.myapp.sqrt', [vals1[i]]).then(
                        function(res) {
                            test.log("Result:", res);
                        },
                        function(err) {
                            test.log("Error:", err.error, err.args, err.kwargs);
                        }
                    ));
                }

                when.all(pl2).then(function() {
                    test.log("All finished.");
                    connection.close();

                    var chk = test.check()
                    assert(!chk, chk);
                    done();
                });
            },
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:28,代码来源:test_rpc_error.ts

示例6: it

it('should publish on wildcard subscriptions', function(done) {

    // testcase.expect(1);

    var test = new testutil.Testlog("test/test_pubsub_wildcard_sub.txt");

    var dl = testutil.connect_n(2);

    when.all(dl).then(
        function(res) {
            test.log("all sessions connected");

            var session1 = res[0];
            var session2 = res[1];
            var received = 0;

            function onevent1(args) {
                test.log("Got event:", args);
                received += 1;
                if (received >= 2) {
                    test.log("Closing ..");

                    session1.leave();
                    session2.leave();

                    var chk = test.check()
                    assert(!chk, chk);
                    done();
                }
            }

            var options = { match: 'wildcard' };
            var msg = "Hello wildcard pattern subscriber!";
            var counter = 0;

            session2.subscribe('com.example..create', onevent1, options).then(
                function(subscription) {
                    // these are all received
                    session1.publish('com.example.foobar.create', [msg, counter++]);
                    session1.publish('com.example.1.create', [msg, counter++]);

                    // these are not received
                    session1.publish('com.example.foobar.delete', [msg, counter++]);
                    session1.publish('com.example.foobar.create2', [msg, counter++]);
                    session1.publish('com.example.foobar.create.barbaz', [msg, counter++]);
                    session1.publish('com.example.foobar', [msg, counter++]);
                    session1.publish('com.example.create', [msg, counter++]);
                    session1.publish('com.example', [msg, counter++]);
                },
                function(err) {
                    test.log(err);
                }
            );
        },
        function(err) {
            test.log(err);
        }
    );
});
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:59,代码来源:test_pubsub_wildcard_sub.ts

示例7: it

it('should consider the pubsub options', function(done) {

    // testcase.expect(1);

    var test = new testutil.Testlog("test/test_pubsub_options.txt");

    var dl = testutil.connect_n(2);

    when.all(dl).then(
        function(res) {
            test.log("all sessions connected");

            var session1 = res[0];
            var session2 = res[1];

            var counter = 0;

            var t1 = setInterval(function() {
                var options = { acknowledge: true, disclose_me: true };

                session1.publish('com.myapp.topic1', [counter], {}, options).then(
                    function(pub) {
                        test.log("event published", typeof (pub), typeof (pub.id));
                    }
                );
                counter += 1;
            }, 100);

            var received = 0;

            var sub;

            function onevent1(args, kwargs, details) {
                test.log("got event:", typeof (details), typeof (details.publication), typeof (details.publisher), details.publisher == session1.id, args[0]);

                received += 1;
                if (received > 5) {
                    test.log("Closing ..");

                    clearInterval(t1);

                    session1.leave();
                    session2.leave();

                    var chk = test.check()
                    assert(!chk, chk);
                    done();
                }
            }

            sub = session2.subscribe('com.myapp.topic1', onevent1);
        },
        function(err) {
            test.log(err);
        }
    );
});
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:57,代码来源:test_pubsub_options.ts

示例8: case3

            function case3() {
                test.log("");
                test.log("Case 3: 'exclude' sessions 2 and 3");
                test.log("==================================");

                var counter = 0;

                var t3 = setInterval(function() {
                    session1.publish('com.myapp.topic3', [counter], {}, { exclude: [session2.id, session3.id] });
                    counter += 1;

                    if (counter > 5) {
                        session1.publish('com.myapp.topic3', [counter]);
                        clearInterval(t3);
                    }
                }, delay);


                var received2 = 0;
                var received3 = 0;

                var session2Finished = when.defer();
                var session3Finished = when.defer();

                var testLog2 = [];
                var testLog3 = [];


                function onevent2(args) {
                    received2 += 1;

                    // testLog2.push("Session 2 got stopper event");
                    session2Finished.resolve(true);
                }

                function onevent3(args) {
                    received3 += 1;

                    // testLog3.push("Session 3 got stopper event");
                    session3Finished.resolve(true);
                }

                when.all([session2Finished.promise, session3Finished.promise]).then(function() {

                    // clearInterval(t3);

                    assert(received2 === 1 && received3 === 1, "Case 3: Both clients received final event");

                    onTestFinished();
                });

                // both sessions subscribe
                session2.subscribe('com.myapp.topic3', onevent2);
                session3.subscribe('com.myapp.topic3', onevent3);


            }
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:57,代码来源:test_pubsub_exclude.ts

示例9: it

it('should pass basic PubSub test', function(done) {

    // testcase.expect(1);

    var test = new testutil.Testlog("test/test_pubsub_basic.txt");

    var dl = testutil.connect_n(2);

    when.all(dl).then(
        function(res) {
            test.log("all sessions connected");

            var session1 = res[0];
            var session2 = res[1];

            var counter = 0;

            var t1 = setInterval(function() {
                test.log("publishing to topic 'com.myapp.topic1': " + counter);
                session1.publish('com.myapp.topic1', [counter]);
                counter += 1;
            }, 100);

            var received = 0;

            var sub;
            function onevent1(args) {
                test.log("Got event:", args[0]);
                received += 1;
                if (received > 5) {
                    test.log("Closing ..");

                    clearInterval(t1);

                    session1.leave();
                    session2.leave();

                    var chk = test.check()
                    assert(!chk, chk);
                    done();
                }
            }

            sub = session2.subscribe('com.myapp.topic1', onevent1);
        },
        function(err) {
            test.log(err);
        }
    );
});
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:50,代码来源:test_pubsub_basic.ts

示例10: it

it('should route RPC requests', function(done) {

    // testcase.expect(3);

    var test = new testutil.Testlog("test/test_rpc_routing.txt");

    var dl = testutil.connect_n(2);

    when.all(dl).then(
        function(res) {
            test.log("all sessions connected");

            var session1 = res[0];
            var session2 = res[1];

            function square(args, kwargs, details) {
                var x = args[0];
                test.log("square() called from session 2", x);
                assert(details.caller == session2.id);
                return x * x;
            }

            session1.register('com.math.square', square).then(
                function(res) {

                    test.log("square() registered on session 1");

                    session2.call('com.math.square', [23], {}, { disclose_me: true }).then(
                        function(res) {
                            test.log("result:", res);

                            session1.leave();
                            session2.leave();

                            assert(res == (23 * 23));

                            var chk = test.check()
                            assert.ok(!chk, chk);

                            done();
                        })
                }
            );
        },
        function(err) {
            test.log(err);
        }
    );
});
开发者ID:michaelbaer,项目名称:autobahn-ts,代码行数:49,代码来源:test_rpc_routing.ts


注:本文中的when.all函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。