mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
debt - less TPromise
This commit is contained in:
@@ -5,16 +5,15 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { IPager, PagedModel } from 'vs/base/common/paging';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { isPromiseCanceledError, canceled } from 'vs/base/common/errors';
|
||||
|
||||
function getPage(pageIndex: number, cancellationToken: CancellationToken): Thenable<number[]> {
|
||||
if (cancellationToken.isCancellationRequested) {
|
||||
return TPromise.wrapError(canceled());
|
||||
return Promise.reject(canceled());
|
||||
}
|
||||
|
||||
return TPromise.as([0, 1, 2, 3, 4].map(i => i + (pageIndex * 5)));
|
||||
return Promise.resolve([0, 1, 2, 3, 4].map(i => i + (pageIndex * 5)));
|
||||
}
|
||||
|
||||
class TestPager implements IPager<number> {
|
||||
@@ -102,7 +101,7 @@ suite('PagedModel', () => {
|
||||
test('preemptive cancellation works', async function () {
|
||||
const pager = new TestPager(() => {
|
||||
assert(false);
|
||||
return TPromise.wrap([]);
|
||||
return Promise.resolve([]);
|
||||
});
|
||||
|
||||
const model = new PagedModel(pager);
|
||||
@@ -117,7 +116,7 @@ suite('PagedModel', () => {
|
||||
});
|
||||
|
||||
test('cancellation works', function () {
|
||||
const pager = new TestPager((_, token) => new TPromise((_, e) => {
|
||||
const pager = new TestPager((_, token) => new Promise((_, e) => {
|
||||
token.onCancellationRequested(() => e(canceled()));
|
||||
}));
|
||||
|
||||
@@ -140,7 +139,7 @@ suite('PagedModel', () => {
|
||||
const pager = new TestPager((pageIndex, token) => {
|
||||
state = 'resolving';
|
||||
|
||||
return new TPromise((_, e) => {
|
||||
return new Promise((_, e) => {
|
||||
token.onCancellationRequested(() => {
|
||||
state = 'idle';
|
||||
e(canceled());
|
||||
@@ -180,6 +179,6 @@ suite('PagedModel', () => {
|
||||
}, 10);
|
||||
}, 10);
|
||||
|
||||
return TPromise.join([promise1, promise2]);
|
||||
return Promise.all([promise1, promise2]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user