Skip to content

Commit 9215e77

Browse files
author
Benjamin Pasero
committed
debt - remove some WinJS.timeout() calls
1 parent 48e118b commit 9215e77

10 files changed

Lines changed: 73 additions & 85 deletions

File tree

src/vs/base/browser/ui/progressbar/progressbar.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
'use strict';
77

88
import 'vs/css!./progressbar';
9-
import { TPromise, ValueCallback } from 'vs/base/common/winjs.base';
109
import * as assert from 'vs/base/common/assert';
1110
import { Builder, $ } from 'vs/base/browser/builder';
12-
import * as DOM from 'vs/base/browser/dom';
1311
import { Disposable } from 'vs/base/common/lifecycle';
1412
import { Color } from 'vs/base/common/color';
1513
import { mixin } from 'vs/base/common/objects';
@@ -41,7 +39,6 @@ export class ProgressBar extends Disposable {
4139
private element: Builder;
4240
private bit: HTMLElement;
4341
private totalWork: number;
44-
private animationStopToken: ValueCallback;
4542
private progressBarBackground: Color;
4643

4744
constructor(container: HTMLElement, options?: IProgressBarOptions) {
@@ -60,19 +57,7 @@ export class ProgressBar extends Disposable {
6057
private create(container: HTMLElement): void {
6158
$(container).div({ 'class': css_progress_container }, builder => {
6259
this.element = builder.clone();
63-
64-
builder.div({ 'class': css_progress_bit }).on([DOM.EventType.ANIMATION_START, DOM.EventType.ANIMATION_END, DOM.EventType.ANIMATION_ITERATION], (e: Event) => {
65-
switch (e.type) {
66-
case DOM.EventType.ANIMATION_ITERATION:
67-
if (this.animationStopToken) {
68-
this.animationStopToken(null);
69-
}
70-
break;
71-
}
72-
73-
}, this.toDispose);
74-
75-
this.bit = builder.getHTMLElement();
60+
this.bit = builder.div({ 'class': css_progress_bit }).getHTMLElement();
7661
});
7762

7863
this.applyStyles();
@@ -111,7 +96,7 @@ export class ProgressBar extends Disposable {
11196
this.bit.style.width = 'inherit';
11297

11398
if (delayed) {
114-
TPromise.timeout(200).then(() => this.off());
99+
setTimeout(200, () => this.off());
115100
} else {
116101
this.off();
117102
}
@@ -121,7 +106,7 @@ export class ProgressBar extends Disposable {
121106
else {
122107
this.bit.style.opacity = '0';
123108
if (delayed) {
124-
TPromise.timeout(200).then(() => this.off());
109+
setTimeout(200, () => this.off());
125110
} else {
126111
this.off();
127112
}

src/vs/base/parts/quickopen/browser/quickOpenWidget.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import 'vs/css!./quickopen';
88
import * as nls from 'vs/nls';
9-
import { TPromise } from 'vs/base/common/winjs.base';
109
import * as platform from 'vs/base/common/platform';
1110
import * as types from 'vs/base/common/types';
1211
import * as errors from 'vs/base/common/errors';
@@ -980,19 +979,16 @@ export class QuickOpenWidget extends Disposable implements IModelProvider {
980979
}
981980

982981
this.isLoosingFocus = true;
983-
TPromise.timeout(0).then(() => {
984-
if (!this.isLoosingFocus) {
985-
return;
986-
}
987-
if (this.isDisposed) {
982+
setTimeout(() => {
983+
if (!this.isLoosingFocus || this.isDisposed) {
988984
return;
989985
}
990986

991987
const veto = this.callbacks.onFocusLost && this.callbacks.onFocusLost();
992988
if (!veto) {
993989
this.hide(HideReason.FOCUS_LOST);
994990
}
995-
});
991+
}, 0);
996992
}
997993

998994
dispose(): void {

src/vs/code/electron-main/app.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import { MenubarService } from 'vs/platform/menubar/electron-main/menubarService
6565
import { MenubarChannel } from 'vs/platform/menubar/common/menubarIpc';
6666
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
6767
import { CodeMenu } from 'vs/code/electron-main/menus';
68+
import { RunOnceScheduler } from 'vs/base/common/async';
6869

6970
export class CodeApplication {
7071

@@ -529,7 +530,9 @@ export class CodeApplication {
529530
this.historyMainService.onRecentlyOpenedChange(() => this.historyMainService.updateWindowsJumpList());
530531

531532
// Start shared process after a while
532-
TPromise.timeout(3000).then(() => this.sharedProcess.spawn());
533+
const sharedProcess = new RunOnceScheduler(() => this.sharedProcess.spawn(), 3000);
534+
sharedProcess.schedule();
535+
this.toDispose.push(sharedProcess);
533536
}
534537

535538
private dispose(): void {

src/vs/editor/standalone/browser/quickOpen/quickCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class EditorActionCommandEntry extends QuickOpenEntryGroup {
5050
if (mode === Mode.OPEN) {
5151

5252
// Use a timeout to give the quick open widget a chance to close itself first
53-
TPromise.timeout(50).done(() => {
53+
setTimeout(() => {
5454

5555
// Some actions are enabled only when editor has focus
5656
this.editor.focus();
@@ -61,7 +61,7 @@ export class EditorActionCommandEntry extends QuickOpenEntryGroup {
6161
} catch (error) {
6262
onUnexpectedError(error);
6363
}
64-
}, onUnexpectedError);
64+
}, 50);
6565

6666
return true;
6767
}

src/vs/workbench/browser/parts/editor/editorStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ export class ChangeModeAction extends Action {
999999
};
10001000
});
10011001

1002-
TPromise.timeout(50 /* quick open is sensitive to being opened so soon after another */).done(() => {
1002+
setTimeout(() => {
10031003
this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || basename) }).done(language => {
10041004
if (language) {
10051005
const fileAssociationsConfig = this.configurationService.inspect(FILES_ASSOCIATIONS_CONFIG);
@@ -1027,8 +1027,8 @@ export class ChangeModeAction extends Action {
10271027

10281028
this.configurationService.updateValue(FILES_ASSOCIATIONS_CONFIG, currentAssociations, target);
10291029
}
1030-
});
1031-
});
1030+
}, error => errors.onUnexpectedError(error));
1031+
}, 50 /* quick open is sensitive to being opened so soon after another */);
10321032
}
10331033
}
10341034

src/vs/workbench/browser/parts/quickopen/quickOpenController.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { Dimension, addClass } from 'vs/base/browser/dom';
5656
import { IEditorService, ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
5757
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
5858
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
59-
import { isThenable } from 'vs/base/common/async';
59+
import { isThenable, timeout } from 'vs/base/common/async';
6060

6161
const HELP_PREFIX = '?';
6262

@@ -394,11 +394,11 @@ export class QuickOpenController extends Component implements IQuickOpenService
394394
});
395395

396396
// Progress if task takes a long time
397-
TPromise.timeout(800).then(() => {
397+
setTimeout(() => {
398398
if (!picksPromiseDone && this.currentPickerToken === currentPickerToken) {
399399
this.pickOpenWidget.getProgressBar().infinite().show();
400400
}
401-
});
401+
}, 800);
402402

403403
// Show picker empty if resolving takes a while
404404
if (!picksPromiseDone) {
@@ -670,11 +670,11 @@ export class QuickOpenController extends Component implements IQuickOpenService
670670
this.previousActiveHandlerDescriptor = handlerDescriptor;
671671

672672
// Progress if task takes a long time
673-
TPromise.timeout(instantProgress ? 0 : 800).then(() => {
673+
setTimeout(() => {
674674
if (!resultPromiseDone && currentResultToken === this.currentResultToken) {
675675
this.quickOpenWidget.getProgressBar().infinite().show();
676676
}
677-
});
677+
}, instantProgress ? 0 : 800);
678678

679679
// Promise done handling
680680
resultPromise.done(() => {
@@ -709,7 +709,14 @@ export class QuickOpenController extends Component implements IQuickOpenService
709709
const previousInput = this.quickOpenWidget.getInput();
710710
const wasShowingHistory = previousInput && previousInput.entries && previousInput.entries.some(e => e instanceof EditorHistoryEntry || e instanceof EditorHistoryEntryGroup);
711711
if (wasShowingHistory || matchingHistoryEntries.length > 0) {
712-
(resolvedHandler.hasShortResponseTime() ? TPromise.timeout(QuickOpenController.MAX_SHORT_RESPONSE_TIME) : TPromise.as(undefined)).then(() => {
712+
let responseDelay: Thenable<void>;
713+
if (resolvedHandler.hasShortResponseTime()) {
714+
responseDelay = timeout(QuickOpenController.MAX_SHORT_RESPONSE_TIME);
715+
} else {
716+
responseDelay = Promise.resolve(void 0);
717+
}
718+
719+
responseDelay.then(() => {
713720
if (this.currentResultToken === currentResultToken && !inputSet) {
714721
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
715722
inputSet = true;

src/vs/workbench/parts/files/browser/editors/fileEditorTracker.ts

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

7-
import { TPromise } from 'vs/base/common/winjs.base';
87
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
98
import URI from 'vs/base/common/uri';
109
import * as resources from 'vs/base/common/resources';
@@ -27,7 +26,7 @@ import { IWindowService } from 'vs/platform/windows/common/windows';
2726
import { BINARY_FILE_EDITOR_ID } from 'vs/workbench/parts/files/common/files';
2827
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2928
import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/group/common/editorGroupsService';
30-
import { ResourceQueue } from 'vs/base/common/async';
29+
import { ResourceQueue, timeout } from 'vs/base/common/async';
3130
import { onUnexpectedError } from 'vs/base/common/errors';
3231

3332
export class FileEditorTracker extends Disposable implements IWorkbenchContribution {
@@ -170,14 +169,14 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
170169
// file is really gone and not just a faulty file event.
171170
// This only applies to external file events, so we need to check for the isExternal
172171
// flag.
173-
let checkExists: TPromise<boolean>;
172+
let checkExists: Thenable<boolean>;
174173
if (isExternal) {
175-
checkExists = TPromise.timeout(100).then(() => this.fileService.existsFile(resource));
174+
checkExists = timeout(100).then(() => this.fileService.existsFile(resource));
176175
} else {
177-
checkExists = TPromise.as(false);
176+
checkExists = Promise.resolve(false);
178177
}
179178

180-
checkExists.done(exists => {
179+
checkExists.then(exists => {
181180
if (!exists && !editor.isDisposed()) {
182181
editor.dispose();
183182
} else if (this.environmentService.verbose) {

src/vs/workbench/parts/quickopen/browser/commandsHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ abstract class BaseCommandEntry extends QuickOpenEntryGroup {
293293
this.onBeforeRun(this.commandId);
294294

295295
// Use a timeout to give the quick open widget a chance to close itself first
296-
TPromise.timeout(50).done(() => {
296+
setTimeout(() => {
297297
if (action && (!(action instanceof Action) || action.enabled)) {
298298
try {
299299
/* __GDPR__
@@ -314,7 +314,7 @@ abstract class BaseCommandEntry extends QuickOpenEntryGroup {
314314
} else {
315315
this.notificationService.info(nls.localize('actionNotEnabled', "Command '{0}' is not enabled in the current context.", this.getLabel()));
316316
}
317-
}, err => this.onError(err));
317+
}, 50);
318318
}
319319

320320
private onError(error?: Error): void {

src/vs/workbench/services/contextview/electron-browser/contextmenuService.ts

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,44 @@ export class ContextMenuService extends Disposable implements IContextMenuServic
3737

3838
showContextMenu(delegate: IContextMenuDelegate): void {
3939
delegate.getActions().then(actions => {
40-
if (!actions.length) {
41-
return TPromise.as(null);
42-
}
43-
44-
return TPromise.timeout(0).then(() => { // https://github.com/Microsoft/vscode/issues/3638
45-
const onHide = once(() => {
46-
if (delegate.onHide) {
47-
delegate.onHide(undefined);
48-
}
40+
if (actions.length) {
41+
setTimeout(() => {
42+
const onHide = once(() => {
43+
if (delegate.onHide) {
44+
delegate.onHide(undefined);
45+
}
4946

50-
this._onDidContextMenu.fire();
51-
});
47+
this._onDidContextMenu.fire();
48+
});
5249

53-
const menu = this.createMenu(delegate, actions, onHide);
54-
const anchor = delegate.getAnchor();
55-
let x: number, y: number;
50+
const menu = this.createMenu(delegate, actions, onHide);
51+
const anchor = delegate.getAnchor();
52+
let x: number, y: number;
5653

57-
if (dom.isHTMLElement(anchor)) {
58-
let elementPosition = dom.getDomNodePagePosition(anchor);
54+
if (dom.isHTMLElement(anchor)) {
55+
let elementPosition = dom.getDomNodePagePosition(anchor);
5956

60-
x = elementPosition.left;
61-
y = elementPosition.top + elementPosition.height;
62-
} else {
63-
const pos = <{ x: number; y: number; }>anchor;
64-
x = pos.x + 1; /* prevent first item from being selected automatically under mouse */
65-
y = pos.y;
66-
}
67-
68-
let zoom = webFrame.getZoomFactor();
69-
x *= zoom;
70-
y *= zoom;
57+
x = elementPosition.left;
58+
y = elementPosition.top + elementPosition.height;
59+
} else {
60+
const pos = <{ x: number; y: number; }>anchor;
61+
x = pos.x + 1; /* prevent first item from being selected automatically under mouse */
62+
y = pos.y;
63+
}
7164

72-
menu.popup({
73-
window: remote.getCurrentWindow(),
74-
x: Math.floor(x),
75-
y: Math.floor(y),
76-
positioningItem: delegate.autoSelectFirstItem ? 0 : void 0,
77-
callback: () => onHide()
78-
});
79-
});
65+
let zoom = webFrame.getZoomFactor();
66+
x *= zoom;
67+
y *= zoom;
68+
69+
menu.popup({
70+
window: remote.getCurrentWindow(),
71+
x: Math.floor(x),
72+
y: Math.floor(y),
73+
positioningItem: delegate.autoSelectFirstItem ? 0 : void 0,
74+
callback: () => onHide()
75+
});
76+
}, 0); // https://github.com/Microsoft/vscode/issues/3638
77+
}
8078
});
8179
}
8280

src/vs/workbench/services/textfile/common/textFileEditorModel.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
2525
import { IModeService } from 'vs/editor/common/services/modeService';
2626
import { IModelService } from 'vs/editor/common/services/modelService';
2727
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
28-
import { RunOnceScheduler } from 'vs/base/common/async';
28+
import { RunOnceScheduler, timeout } from 'vs/base/common/async';
2929
import { ITextBufferFactory } from 'vs/editor/common/model';
3030
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
3131
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
@@ -153,24 +153,24 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
153153
}
154154

155155
if (fileEventImpactsModel && this.inOrphanMode !== newInOrphanModeGuess) {
156-
let checkOrphanedPromise: TPromise<boolean>;
156+
let checkOrphanedPromise: Thenable<boolean>;
157157
if (newInOrphanModeGuess) {
158158
// We have received reports of users seeing delete events even though the file still
159159
// exists (network shares issue: https://github.com/Microsoft/vscode/issues/13665).
160160
// Since we do not want to mark the model as orphaned, we have to check if the
161161
// file is really gone and not just a faulty file event.
162-
checkOrphanedPromise = TPromise.timeout(100).then(() => {
162+
checkOrphanedPromise = timeout(100).then(() => {
163163
if (this.disposed) {
164164
return true;
165165
}
166166

167167
return this.fileService.existsFile(this.resource).then(exists => !exists);
168168
});
169169
} else {
170-
checkOrphanedPromise = TPromise.as(false);
170+
checkOrphanedPromise = Promise.resolve(false);
171171
}
172172

173-
checkOrphanedPromise.done(newInOrphanModeValidated => {
173+
checkOrphanedPromise.then(newInOrphanModeValidated => {
174174
if (this.inOrphanMode !== newInOrphanModeValidated && !this.disposed) {
175175
this.setOrphaned(newInOrphanModeValidated);
176176
}

0 commit comments

Comments
 (0)