本文整理汇总了TypeScript中vs/base/common/async.Throttler类的典型用法代码示例。如果您正苦于以下问题:TypeScript Throttler类的具体用法?TypeScript Throttler怎么用?TypeScript Throttler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Throttler类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('Throttler - last factory should be the one getting called', function () {
let factoryFactory = (n: number) => () => {
return async.timeout(0).then(() => n);
};
let throttler = new async.Throttler();
let promises: Thenable<any>[] = [];
promises.push(throttler.queue(factoryFactory(1)).then((n) => { assert.equal(n, 1); }));
promises.push(throttler.queue(factoryFactory(2)).then((n) => { assert.equal(n, 3); }));
promises.push(throttler.queue(factoryFactory(3)).then((n) => { assert.equal(n, 3); }));
return Promise.all(promises);
});
示例2: test
test('Throttler', function () {
let count = 0;
let factory = () => {
return TPromise.timeout(0).then(() => {
return ++count;
});
};
let throttler = new Async.Throttler();
return TPromise.join([
throttler.queue(factory).then((result) => { assert.equal(result, 1); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); })
]).then(() => {
TPromise.join([
throttler.queue(factory).then((result) => { assert.equal(result, 3); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); })
]);
});
});
示例3:
]).then(() => {
return Promise.all([
throttler.queue(factory).then((result) => { assert.equal(result, 3); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); })
]);
});
示例4:
]).then(() => {
TPromise.join([
throttler.queue(factory).then((result) => { assert.equal(result, 3); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); })
]);
});