Skip to content

Commit 1b2aab7

Browse files
committed
remove remaining users of cancel and cancel-callback, microsoft#56137
1 parent 677b68d commit 1b2aab7

6 files changed

Lines changed: 60 additions & 146 deletions

File tree

src/vs/base/common/async.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ export class Throttler {
129129

130130
this.queuedPromise = new TPromise(c => {
131131
this.activePromise.then(onComplete, onComplete).then(c);
132-
}, () => {
133-
this.activePromise.cancel();
134132
});
135133
}
136134

@@ -149,8 +147,6 @@ export class Throttler {
149147
this.activePromise = null;
150148
e(err);
151149
});
152-
}, () => {
153-
this.activePromise.cancel();
154150
});
155151
}
156152
}
@@ -192,13 +188,14 @@ export class Delayer<T> {
192188

193189
private timeout: number;
194190
private completionPromise: TPromise;
195-
private onSuccess: ValueCallback;
191+
private doResolve: ValueCallback;
192+
private doReject: (err: any) => void;
196193
private task: ITask<T | TPromise<T>>;
197194

198195
constructor(public defaultDelay: number) {
199196
this.timeout = null;
200197
this.completionPromise = null;
201-
this.onSuccess = null;
198+
this.doResolve = null;
202199
this.task = null;
203200
}
204201

@@ -207,13 +204,12 @@ export class Delayer<T> {
207204
this.cancelTimeout();
208205

209206
if (!this.completionPromise) {
210-
this.completionPromise = new TPromise((c) => {
211-
this.onSuccess = c;
212-
}, () => {
213-
// no-op
207+
this.completionPromise = new TPromise((c, e) => {
208+
this.doResolve = c;
209+
this.doReject = e;
214210
}).then(() => {
215211
this.completionPromise = null;
216-
this.onSuccess = null;
212+
this.doResolve = null;
217213
const task = this.task;
218214
this.task = null;
219215

@@ -223,7 +219,7 @@ export class Delayer<T> {
223219

224220
this.timeout = setTimeout(() => {
225221
this.timeout = null;
226-
this.onSuccess(null);
222+
this.doResolve(null);
227223
}, delay);
228224

229225
return this.completionPromise;
@@ -237,7 +233,7 @@ export class Delayer<T> {
237233
this.cancelTimeout();
238234

239235
if (this.completionPromise) {
240-
this.completionPromise.cancel();
236+
this.doReject(errors.canceled());
241237
this.completionPromise = null;
242238
}
243239
}
@@ -302,26 +298,6 @@ export class Barrier {
302298
}
303299
}
304300

305-
export class ShallowCancelThenPromise<T> extends TPromise<T> {
306-
307-
constructor(outer: TPromise<T>) {
308-
309-
let completeCallback: ValueCallback,
310-
errorCallback: ErrorCallback;
311-
312-
super((c, e) => {
313-
completeCallback = c;
314-
errorCallback = e;
315-
}, () => {
316-
// cancel this promise but not the
317-
// outer promise
318-
errorCallback(errors.canceled());
319-
});
320-
321-
outer.then(completeCallback, errorCallback);
322-
}
323-
}
324-
325301
/**
326302
* Replacement for `WinJS.TPromise.timeout`.
327303
*/

src/vs/base/common/worker/simpleWorker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import { transformErrorForSerialization } from 'vs/base/common/errors';
88
import { Disposable } from 'vs/base/common/lifecycle';
99
import { ErrorCallback, TPromise, ValueCallback } from 'vs/base/common/winjs.base';
10-
import { ShallowCancelThenPromise } from 'vs/base/common/async';
1110
import { isWeb } from 'vs/base/common/platform';
1211

1312
const INITIALIZE = '$initialize';
@@ -266,8 +265,7 @@ export class SimpleWorkerClient<T> extends Disposable {
266265
}
267266

268267
public getProxyObject(): TPromise<T> {
269-
// Do not allow chaining promises to cancel the proxy creation
270-
return new ShallowCancelThenPromise(this._lazyProxy);
268+
return this._lazyProxy;
271269
}
272270

273271
private _request(method: string, args: any[]): TPromise<any> {

src/vs/base/parts/tree/browser/treeModel.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,11 @@ export class Lock {
8484
var lock = this.getLock(item);
8585

8686
if (lock) {
87-
var unbindListener: IDisposable;
88-
8987
return new WinJS.TPromise((c, e) => {
90-
unbindListener = once(lock.onDispose)(() => {
88+
once(lock.onDispose)(() => {
9189
return this.run(item, fn).then(c, e);
9290
});
93-
}, () => { unbindListener.dispose(); });
91+
});
9492
}
9593

9694
var result: WinJS.Promise;

src/vs/base/test/common/async.test.ts

Lines changed: 42 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ suite('Async', () => {
4141
return result;
4242
});
4343

44-
test('Cancel callback behaviour', async function () {
45-
let withCancelCallback = new TPromise(() => { }, () => { });
46-
let withoutCancelCallback = new TPromise(() => { });
44+
// test('Cancel callback behaviour', async function () {
45+
// let withCancelCallback = new WinJsPromise(() => { }, () => { });
46+
// let withoutCancelCallback = new TPromise(() => { });
4747

48-
withCancelCallback.cancel();
49-
withoutCancelCallback.cancel();
48+
// withCancelCallback.cancel();
49+
// (withoutCancelCallback as WinJsPromise).cancel();
5050

51-
await withCancelCallback.then(undefined, err => { assert.ok(isPromiseCanceledError(err)); });
52-
await withoutCancelCallback.then(undefined, err => { assert.ok(isPromiseCanceledError(err)); });
53-
});
51+
// await withCancelCallback.then(undefined, err => { assert.ok(isPromiseCanceledError(err)); });
52+
// await withoutCancelCallback.then(undefined, err => { assert.ok(isPromiseCanceledError(err)); });
53+
// });
5454

5555
// Cancelling a sync cancelable promise will fire the cancelled token.
5656
// Also, every `then` callback runs in another execution frame.
@@ -97,49 +97,49 @@ suite('Async', () => {
9797
return promise.then(() => assert.deepEqual(order, ['in callback', 'afterCreate', 'cancelled', 'afterCancel', 'finally']));
9898
});
9999

100-
// Cancelling a sync tpromise will NOT cancel the promise, since it has resolved already.
101-
// Every `then` callback runs sync in the same execution frame, thus `finally` executes
102-
// before `afterCancel`.
103-
test('TPromise execution order (sync)', function () {
104-
const order = [];
105-
let promise = new TPromise(resolve => {
106-
order.push('in executor');
107-
resolve(1234);
108-
}, () => order.push('cancelled'));
100+
// // Cancelling a sync tpromise will NOT cancel the promise, since it has resolved already.
101+
// // Every `then` callback runs sync in the same execution frame, thus `finally` executes
102+
// // before `afterCancel`.
103+
// test('TPromise execution order (sync)', function () {
104+
// const order = [];
105+
// let promise = new WinJsPromise(resolve => {
106+
// order.push('in executor');
107+
// resolve(1234);
108+
// }, () => order.push('cancelled'));
109109

110-
order.push('afterCreate');
110+
// order.push('afterCreate');
111111

112-
promise = promise
113-
.then(null, err => null)
114-
.then(() => order.push('finally'));
112+
// promise = promise
113+
// .then(null, err => null)
114+
// .then(() => order.push('finally'));
115115

116-
promise.cancel();
117-
order.push('afterCancel');
116+
// promise.cancel();
117+
// order.push('afterCancel');
118118

119-
return promise.then(() => assert.deepEqual(order, ['in executor', 'afterCreate', 'finally', 'afterCancel']));
120-
});
119+
// return promise.then(() => assert.deepEqual(order, ['in executor', 'afterCreate', 'finally', 'afterCancel']));
120+
// });
121121

122-
// Cancelling an async tpromise will cancel the promise.
123-
// Every `then` callback runs sync on the same execution frame as the `cancel` call,
124-
// so finally still executes before `afterCancel`.
125-
test('TPromise execution order (async)', function () {
126-
const order = [];
127-
let promise = new TPromise(resolve => {
128-
order.push('in executor');
129-
setTimeout(() => resolve(1234));
130-
}, () => order.push('cancelled'));
122+
// // Cancelling an async tpromise will cancel the promise.
123+
// // Every `then` callback runs sync on the same execution frame as the `cancel` call,
124+
// // so finally still executes before `afterCancel`.
125+
// test('TPromise execution order (async)', function () {
126+
// const order = [];
127+
// let promise = new WinJsPromise(resolve => {
128+
// order.push('in executor');
129+
// setTimeout(() => resolve(1234));
130+
// }, () => order.push('cancelled'));
131131

132-
order.push('afterCreate');
132+
// order.push('afterCreate');
133133

134-
promise = promise
135-
.then(null, err => null)
136-
.then(() => order.push('finally'));
134+
// promise = promise
135+
// .then(null, err => null)
136+
// .then(() => order.push('finally'));
137137

138-
promise.cancel();
139-
order.push('afterCancel');
138+
// promise.cancel();
139+
// order.push('afterCancel');
140140

141-
return promise.then(() => assert.deepEqual(order, ['in executor', 'afterCreate', 'cancelled', 'finally', 'afterCancel']));
142-
});
141+
// return promise.then(() => assert.deepEqual(order, ['in executor', 'afterCreate', 'cancelled', 'finally', 'afterCancel']));
142+
// });
143143

144144
test('cancelablePromise - get inner result', async function () {
145145
let promise = async.createCancelablePromise(token => {
@@ -190,63 +190,6 @@ suite('Async', () => {
190190
});
191191
});
192192

193-
test('Throttler - cancel should not cancel other promises', function () {
194-
let count = 0;
195-
let factory = () => TPromise.wrap(async.timeout(0)).then(() => ++count);
196-
197-
let throttler = new async.Throttler();
198-
let p1: TPromise;
199-
200-
const p = TPromise.join([
201-
p1 = throttler.queue(factory).then((result) => { assert(false, 'should not be here, 1'); }, () => { assert(true, 'yes, it was cancelled'); }),
202-
throttler.queue(factory).then((result) => { assert.equal(result, 1); }, () => { assert(false, 'should not be here, 2'); }),
203-
throttler.queue(factory).then((result) => { assert.equal(result, 1); }, () => { assert(false, 'should not be here, 3'); }),
204-
throttler.queue(factory).then((result) => { assert.equal(result, 1); }, () => { assert(false, 'should not be here, 4'); })
205-
]);
206-
207-
p1.cancel();
208-
209-
return p;
210-
});
211-
212-
test('Throttler - cancel the first queued promise should not cancel other promises', function () {
213-
let count = 0;
214-
let factory = () => TPromise.wrap(async.timeout(0)).then(() => ++count);
215-
216-
let throttler = new async.Throttler();
217-
let p2: TPromise;
218-
219-
const p = TPromise.join([
220-
throttler.queue(factory).then((result) => { assert.equal(result, 1); }, () => { assert(false, 'should not be here, 1'); }),
221-
p2 = throttler.queue(factory).then((result) => { assert(false, 'should not be here, 2'); }, () => { assert(true, 'yes, it was cancelled'); }),
222-
throttler.queue(factory).then((result) => { assert.equal(result, 2); }, () => { assert(false, 'should not be here, 3'); }),
223-
throttler.queue(factory).then((result) => { assert.equal(result, 2); }, () => { assert(false, 'should not be here, 4'); })
224-
]);
225-
226-
p2.cancel();
227-
228-
return p;
229-
});
230-
231-
test('Throttler - cancel in the middle should not cancel other promises', function () {
232-
let count = 0;
233-
let factory = () => TPromise.wrap(async.timeout(0)).then(() => ++count);
234-
235-
let throttler = new async.Throttler();
236-
let p3: TPromise;
237-
238-
const p = TPromise.join([
239-
throttler.queue(factory).then((result) => { assert.equal(result, 1); }, () => { assert(false, 'should not be here, 1'); }),
240-
throttler.queue(factory).then((result) => { assert.equal(result, 2); }, () => { assert(false, 'should not be here, 2'); }),
241-
p3 = throttler.queue(factory).then((result) => { assert(false, 'should not be here, 3'); }, () => { assert(true, 'yes, it was cancelled'); }),
242-
throttler.queue(factory).then((result) => { assert.equal(result, 2); }, () => { assert(false, 'should not be here, 4'); })
243-
]);
244-
245-
p3.cancel();
246-
247-
return p;
248-
});
249-
250193
test('Throttler - last factory should be the one getting called', function () {
251194
let factoryFactory = (n: number) => () => {
252195
return TPromise.wrap(async.timeout(0)).then(() => n);

src/vs/editor/common/services/editorWorkerServiceImpl.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7-
import { IntervalTimer, ShallowCancelThenPromise } from 'vs/base/common/async';
7+
import { IntervalTimer } from 'vs/base/common/async';
88
import { Disposable, IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
99
import { URI } from 'vs/base/common/uri';
1010
import { TPromise } from 'vs/base/common/winjs.base';
@@ -321,7 +321,7 @@ class SynchronousWorkerClient<T extends IDisposable> implements IWorkerClient<T>
321321
}
322322

323323
public getProxyObject(): TPromise<T> {
324-
return new ShallowCancelThenPromise(this._proxyObj);
324+
return this._proxyObj;
325325
}
326326
}
327327

@@ -356,11 +356,11 @@ export class EditorWorkerClient extends Disposable {
356356
}
357357

358358
protected _getProxy(): TPromise<EditorSimpleWorkerImpl> {
359-
return new ShallowCancelThenPromise(this._getOrCreateWorker().getProxyObject().then(null, (err) => {
359+
return this._getOrCreateWorker().getProxyObject().then(null, (err) => {
360360
logOnceWebWorkerWarning(err);
361361
this._worker = new SynchronousWorkerClient(new EditorSimpleWorkerImpl(null));
362362
return this._getOrCreateWorker().getProxyObject();
363-
}));
363+
});
364364
}
365365

366366
private _getOrCreateModelManager(proxy: EditorSimpleWorkerImpl): EditorModelManager {

src/vs/editor/common/services/webWorker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7-
import { ShallowCancelThenPromise } from 'vs/base/common/async';
87
import { URI } from 'vs/base/common/uri';
98
import { TPromise } from 'vs/base/common/winjs.base';
109
import { IModelService } from 'vs/editor/common/services/modelService';
@@ -68,7 +67,7 @@ class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWork
6867

6968
private _getForeignProxy(): TPromise<T> {
7069
if (!this._foreignProxy) {
71-
this._foreignProxy = new ShallowCancelThenPromise(this._getProxy().then((proxy) => {
70+
this._foreignProxy = this._getProxy().then((proxy) => {
7271
return proxy.loadForeignModule(this._foreignModuleId, this._foreignModuleCreateData).then((foreignMethods) => {
7372
this._foreignModuleId = null;
7473
this._foreignModuleCreateData = null;
@@ -91,7 +90,7 @@ class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWork
9190

9291
return foreignProxy;
9392
});
94-
}));
93+
});
9594
}
9695
return this._foreignProxy;
9796
}

0 commit comments

Comments
 (0)