本文整理匯總了TypeScript中vs/base/common/async.always函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript always函數的具體用法?TypeScript always怎麽用?TypeScript always使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了always函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('event dispose', () => {
if (process.env['VSCODE_PID']) {
return undefined; // this test fails when run from within VS Code
}
const client = createClient();
const channel = client.getChannel<ITestChannel>('test');
const service = new TestServiceClient(channel);
let count = 0;
const disposable = service.onMarco(() => count++);
const result = service.marco().then(answer => {
assert.equal(answer, 'polo');
assert.equal(count, 1);
return service.marco().then(answer => {
assert.equal(answer, 'polo');
assert.equal(count, 2);
disposable.dispose();
return service.marco().then(answer => {
assert.equal(answer, 'polo');
assert.equal(count, 2);
});
});
});
return always(result, () => client.dispose());
});
示例2: test
test('increasing raw data size', () => {
const client = createClient();
const channel = client.getChannel<ITestChannel>('test');
const service = new TestServiceClient(channel);
const runs = [
{ batches: 250000, dataSize: 100 },
{ batches: 25000, dataSize: 1000 },
{ batches: 2500, dataSize: 10000 },
{ batches: 1250, dataSize: 20000 },
{ batches: 500, dataSize: 50000 },
{ batches: 250, dataSize: 100000 },
{ batches: 125, dataSize: 200000 },
{ batches: 50, dataSize: 500000 },
{ batches: 25, dataSize: 1000000 },
];
let i = 0;
const result = measure(service, 10, 10, 250) // warm-up
.then(() => {
return (function nextRun() {
if (i >= runs.length) {
return;
}
const run = runs[i++];
return measure(service, run.batches, 1, run.dataSize)
.then(() => {
return nextRun();
});
})();
});
return always(result, () => client.dispose());
});
示例3: test
test('event dispose', () => {
const client = createClient();
const channel = client.getChannel<ITestChannel>('test');
const service = new TestServiceClient(channel);
let count = 0;
const disposable = service.onMarco(() => count++);
const result = service.marco().then(answer => {
assert.equal(answer, 'polo');
assert.equal(count, 1);
return service.marco().then(answer => {
assert.equal(answer, 'polo');
assert.equal(count, 2);
disposable.dispose();
return service.marco().then(answer => {
assert.equal(answer, 'polo');
assert.equal(count, 2);
});
});
});
return always(result, () => client.dispose());
});
示例4: test
test('createChannel', () => {
const client = createClient();
const channel = client.getChannel<ITestChannel>('test');
const service = new TestServiceClient(channel);
const result = service.pong('ping').then(r => {
assert.equal(r.incoming, 'ping');
assert.equal(r.outgoing, 'pong');
});
return always(result, () => client.dispose());
});
示例5: test
test('increasing batch size', () => {
if (process.env['VSCODE_PID']) {
return; // TODO@Ben find out why test fails when run from within VS Code
}
const client = createClient();
const channel = client.getChannel<ITestChannel>('test');
const service = new TestServiceClient(channel);
const runs = [
{ batches: 250000, size: 1 },
{ batches: 2500, size: 100 },
{ batches: 500, size: 500 },
{ batches: 250, size: 1000 },
{ batches: 50, size: 5000 },
{ batches: 25, size: 10000 },
// { batches: 10, size: 25000 },
// { batches: 5, size: 50000 },
// { batches: 1, size: 250000 },
];
const dataSizes = [
100,
250,
];
let i = 0, j = 0;
const result = measure(service, 10, 10, 250) // warm-up
.then(() => {
return (function nextRun() {
if (i >= runs.length) {
if (++j >= dataSizes.length) {
return;
}
i = 0;
}
const run = runs[i++];
return measure(service, run.batches, run.size, dataSizes[j])
.then(() => {
return nextRun();
});
})();
});
return always(result, () => client.dispose());
});