Skip to content

Commit

Permalink
TPromise => Promise (#63768)
Browse files Browse the repository at this point in the history
* remove more TPromise (for #53526)

* fix failing webview integration tests on macOS

* do not instantiate TPromise (fix #62716)

* more TPromise removal and fixes

* 💄

* 💄
  • Loading branch information
bpasero committed Nov 26, 2018
1 parent 2779738 commit 55565d4
Show file tree
Hide file tree
Showing 102 changed files with 569 additions and 636 deletions.
3 changes: 0 additions & 3 deletions src/vs/base/common/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@ export class Barrier {
}
}

/**
* Replacement for `WinJS.TPromise.timeout`.
*/
export function timeout(millis: number): CancelablePromise<void>;
export function timeout(millis: number, token: CancellationToken): Thenable<void>;
export function timeout(millis: number, token?: CancellationToken): CancelablePromise<void> | Thenable<void> {
Expand Down
15 changes: 7 additions & 8 deletions src/vs/base/node/extfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { encode, encodeStream } from 'vs/base/node/encoding';
import * as flow from 'vs/base/node/flow';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IDisposable, toDisposable, Disposable } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';

const loop = flow.loop;

Expand Down Expand Up @@ -127,40 +126,40 @@ function doCopyFile(source: string, target: string, mode: number, callback: (err
reader.pipe(writer);
}

export function mkdirp(path: string, mode?: number, token?: CancellationToken): TPromise<boolean> {
export function mkdirp(path: string, mode?: number, token?: CancellationToken): Promise<boolean> {
const mkdir = (): Promise<null> => {
return nfcall(fs.mkdir, path, mode).then(null, (mkdirErr: NodeJS.ErrnoException) => {

// ENOENT: a parent folder does not exist yet
if (mkdirErr.code === 'ENOENT') {
return TPromise.wrapError(mkdirErr);
return Promise.reject(mkdirErr);
}

// Any other error: check if folder exists and
// return normally in that case if its a folder
return nfcall(fs.stat, path).then((stat: fs.Stats) => {
if (!stat.isDirectory()) {
return TPromise.wrapError(new Error(`'${path}' exists and is not a directory.`));
return Promise.reject(new Error(`'${path}' exists and is not a directory.`));
}

return null;
}, statErr => {
return TPromise.wrapError(mkdirErr); // bubble up original mkdir error
return Promise.reject(mkdirErr); // bubble up original mkdir error
});
});
};

// stop at root
if (path === paths.dirname(path)) {
return TPromise.as(true);
return Promise.resolve(true);
}

// recursively mkdir
return mkdir().then(null, (err: NodeJS.ErrnoException) => {

// Respect cancellation
if (token && token.isCancellationRequested) {
return TPromise.as(false);
return Promise.resolve(false);
}

// ENOENT: a parent folder does not exist yet, continue
Expand All @@ -170,7 +169,7 @@ export function mkdirp(path: string, mode?: number, token?: CancellationToken):
}

// Any other error
return TPromise.wrapError(err);
return Promise.reject(err);
});
}

Expand Down
11 changes: 5 additions & 6 deletions src/vs/base/node/pfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ export function readdir(path: string): Promise<string[]> {
return nfcall(extfs.readdir, path);
}

export function exists(path: string): TPromise<boolean> {
return new TPromise(c => fs.exists(path, c));
export function exists(path: string): Promise<boolean> {
return new Promise(c => fs.exists(path, c));
}

export function chmod(path: string, mode: number): Promise<boolean> {
return nfcall(fs.chmod, path, mode);
}

export import mkdirp = extfs.mkdirp;
import { TPromise } from 'vs/base/common/winjs.base';

export function rimraf(path: string): Promise<void> {
return lstat(path).then(stat => {
if (stat.isDirectory() && !stat.isSymbolicLink()) {
return readdir(path)
.then(children => TPromise.join(children.map(child => rimraf(join(path, child)))))
.then(children => Promise.all(children.map(child => rimraf(join(path, child)))))
.then(() => rmdir(path));
} else {
return unlink(path);
Expand All @@ -40,7 +39,7 @@ export function rimraf(path: string): Promise<void> {
return void 0;
}

return TPromise.wrapError(err);
return Promise.reject(err);
});
}

Expand Down Expand Up @@ -148,7 +147,7 @@ function ensureWriteFileQueue(queueKey: string): Queue<void> {
*/
export function readDirsInDir(dirPath: string): Promise<string[]> {
return readdir(dirPath).then(children => {
return TPromise.join(children.map(c => dirExists(join(dirPath, c)))).then(exists => {
return Promise.all(children.map(c => dirExists(join(dirPath, c)))).then(exists => {
return children.filter((_, i) => exists[i]);
});
});
Expand Down
7 changes: 3 additions & 4 deletions src/vs/base/parts/tree/browser/treeDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
import * as platform from 'vs/base/common/platform';
import * as touch from 'vs/base/browser/touch';
Expand Down Expand Up @@ -556,9 +555,9 @@ export class CollapseAllAction extends Action {
super('vs.tree.collapse', nls.localize('collapse', "Collapse"), 'monaco-tree-action collapse-all', enabled);
}

public run(context?: any): TPromise<any> {
public run(context?: any): Thenable<any> {
if (this.viewer.getHighlight()) {
return TPromise.as(null); // Global action disabled if user is in edit mode from another action
return Promise.resolve(); // Global action disabled if user is in edit mode from another action
}

this.viewer.collapseAll();
Expand All @@ -567,6 +566,6 @@ export class CollapseAllAction extends Action {
this.viewer.domFocus();
this.viewer.focusFirst();

return TPromise.as(null);
return Promise.resolve();
}
}
11 changes: 5 additions & 6 deletions src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { mkdirp, readdir, rimraf } from 'vs/base/node/pfs';
import { validatePaths } from 'vs/code/node/paths';
import { LifecycleService, ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
import { Server, serve, connect } from 'vs/base/parts/ipc/node/ipc.net';
import { TPromise } from 'vs/base/common/winjs.base';
import { LaunchChannelClient } from 'vs/platform/launch/electron-main/launchService';
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { InstantiationService } from 'vs/platform/instantiation/node/instantiationService';
Expand Down Expand Up @@ -92,10 +91,10 @@ async function cleanupOlderLogs(environmentService: EnvironmentService): Promise
const oldSessions = allSessions.sort().filter((d, i) => d !== currentLog);
const toDelete = oldSessions.slice(0, Math.max(0, oldSessions.length - 9));

await TPromise.join(toDelete.map(name => rimraf(path.join(logsRoot, name))));
await Promise.all(toDelete.map(name => rimraf(path.join(logsRoot, name))));
}

function createPaths(environmentService: IEnvironmentService): TPromise<any> {
function createPaths(environmentService: IEnvironmentService): Thenable<any> {
const paths = [
environmentService.extensionsPath,
environmentService.nodeCachedDataDir,
Expand All @@ -104,7 +103,7 @@ function createPaths(environmentService: IEnvironmentService): TPromise<any> {
environmentService.workspaceStorageHome
];

return TPromise.join(paths.map(p => p && mkdirp(p))) as TPromise<any>;
return Promise.all(paths.map(path => path && mkdirp(path)));
}

class ExpectedError extends Error {
Expand All @@ -117,8 +116,8 @@ function setupIPC(accessor: ServicesAccessor): Thenable<Server> {
const requestService = accessor.get(IRequestService);
const diagnosticsService = accessor.get(IDiagnosticsService);

function allowSetForegroundWindow(service: LaunchChannelClient): TPromise<void> {
let promise = TPromise.wrap<void>(void 0);
function allowSetForegroundWindow(service: LaunchChannelClient): Thenable<void> {
let promise: Thenable<void> = Promise.resolve();
if (platform.isWindows) {
promise = service.getMainProcessId()
.then(processId => {
Expand Down
29 changes: 15 additions & 14 deletions src/vs/code/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as nls from 'vs/nls';
import { URI } from 'vs/base/common/uri';
import { IStateService } from 'vs/platform/state/common/state';
import { screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -69,12 +68,12 @@ export class CodeWindow extends Disposable implements ICodeWindow {
private currentMenuBarVisibility: MenuBarVisibility;
private representedFilename: string;

private whenReadyCallbacks: TValueCallback<ICodeWindow>[];
private whenReadyCallbacks: { (window: ICodeWindow): void }[];

private currentConfig: IWindowConfiguration;
private pendingLoadConfig: IWindowConfiguration;

private marketplaceHeadersPromise: TPromise<object>;
private marketplaceHeadersPromise: Thenable<object>;

private touchBarGroups: Electron.TouchBarSegmentedControl[];

Expand Down Expand Up @@ -276,19 +275,19 @@ export class CodeWindow extends Disposable implements ICodeWindow {
}
}

ready(): TPromise<ICodeWindow> {
return new TPromise<ICodeWindow>((c) => {
if (this._readyState === ReadyState.READY) {
return c(this);
ready(): Thenable<ICodeWindow> {
return new Promise<ICodeWindow>(resolve => {
if (this.isReady) {
return resolve(this);
}

// otherwise keep and call later when we are ready
this.whenReadyCallbacks.push(c);
this.whenReadyCallbacks.push(resolve);
});
}

get readyState(): ReadyState {
return this._readyState;
get isReady(): boolean {
return this._readyState === ReadyState.READY;
}

private handleMarketplaceRequests(): void {
Expand Down Expand Up @@ -467,7 +466,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {

private registerNavigationListenerOn(command: 'swipe' | 'app-command', back: 'left' | 'browser-backward', forward: 'right' | 'browser-forward', acrossEditors: boolean) {
this._win.on(command as 'swipe' /* | 'app-command' */, (e: Electron.Event, cmd: string) => {
if (this.readyState !== ReadyState.READY) {
if (this._readyState !== ReadyState.READY) {
return; // window must be ready
}

Expand All @@ -489,7 +488,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {

// If this is the first time the window is loaded, we associate the paths
// directly with the window because we assume the loading will just work
if (this.readyState === ReadyState.NONE) {
if (this._readyState === ReadyState.NONE) {
this.currentConfig = config;
}

Expand Down Expand Up @@ -962,9 +961,11 @@ export class CodeWindow extends Disposable implements ICodeWindow {
}

sendWhenReady(channel: string, ...args: any[]): void {
this.ready().then(() => {
if (this.isReady) {
this.send(channel, ...args);
});
} else {
this.ready().then(() => this.send(channel, ...args));
}
}

send(channel: string, ...args: any[]): void {
Expand Down

0 comments on commit 55565d4

Please sign in to comment.