Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PPromise #53487

Merged
merged 24 commits into from Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8ed3b20
remove progress from winjs promises
joaomoreno Jul 3, 2018
8f521a1
remove progress from async
joaomoreno Jul 3, 2018
e08f2b0
Merge branch 'master' into remove-ppromise
joaomoreno Jul 4, 2018
cb1432f
monaco.d.ts
joaomoreno Jul 4, 2018
5800ea2
cleanup types
joaomoreno Jul 4, 2018
88b22b0
cleanup types
joaomoreno Jul 4, 2018
5277fef
cleanup types
joaomoreno Jul 4, 2018
e942f0f
Merge branch 'master' into remove-ppromise
joaomoreno Jul 4, 2018
da9fea2
more PPRomise cleanup
joaomoreno Jul 4, 2018
5384c68
Merge branch 'master' into remove-ppromise
joaomoreno Jul 4, 2018
a25aaa7
remove ProgressCallback from monaco d ts recipe
joaomoreno Jul 4, 2018
3f2c52c
Merge branch 'master' into remove-ppromise
joaomoreno Jul 4, 2018
72f36d7
missing monaco.d.ts
joaomoreno Jul 4, 2018
e4b357a
Merge branch 'master' into remove-ppromise
joaomoreno Jul 5, 2018
8771ff7
remove extra types
joaomoreno Jul 5, 2018
062cdb2
Merge branch 'master' into remove-ppromise
joaomoreno Jul 5, 2018
b5cc822
Merge branch 'master' into remove-ppromise
joaomoreno Jul 5, 2018
58500d0
Merge branch 'master' into remove-ppromise
joaomoreno Jul 9, 2018
f02240f
remove PPromise from IPC
joaomoreno Jul 9, 2018
be80764
Merge branch 'master' into remove-ppromise
joaomoreno Jul 11, 2018
b972256
Merge branch 'master' into remove-ppromise
joaomoreno Aug 6, 2018
5cdfa0c
remove more PPromise usages
joaomoreno Aug 6, 2018
92f76db
Merge remote-tracking branch 'origin/master' into remove-ppromise
joaomoreno Aug 7, 2018
0d15029
Merge branch 'master' into remove-ppromise
joaomoreno Aug 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/monaco/monaco.d.ts.recipe
Expand Up @@ -44,7 +44,7 @@ declare namespace monaco {
}


#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, Promise
#include(vs/base/common/winjs.base.d.ts): TValueCallback, Promise
#include(vs/base/common/cancellation): CancellationTokenSource, CancellationToken
#include(vs/base/common/uri): URI, UriComponents
#include(vs/editor/common/standalone/standaloneBase): KeyCode, KeyMod
Expand Down
44 changes: 17 additions & 27 deletions src/vs/base/common/async.ts
Expand Up @@ -6,7 +6,7 @@
'use strict';

import * as errors from 'vs/base/common/errors';
import { TPromise, ValueCallback, ErrorCallback, ProgressCallback } from 'vs/base/common/winjs.base';
import { TPromise, ValueCallback, ErrorCallback } from 'vs/base/common/winjs.base';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
Expand Down Expand Up @@ -68,7 +68,7 @@ export function createCancelablePromise<T>(callback: (token: CancellationToken)

export function asWinJsPromise<T>(callback: (token: CancellationToken) => T | TPromise<T> | Thenable<T>): TPromise<T> {
let source = new CancellationTokenSource();
return new TPromise<T>((resolve, reject, progress) => {
return new TPromise<T>((resolve, reject) => {
let item = callback(source.token);
if (item instanceof TPromise) {
item.then(result => {
Expand All @@ -77,7 +77,7 @@ export function asWinJsPromise<T>(callback: (token: CancellationToken) => T | TP
}, err => {
source.dispose();
reject(err);
}, progress);
});
} else if (isThenable<T>(item)) {
item.then(result => {
source.dispose();
Expand Down Expand Up @@ -194,30 +194,30 @@ export class Throttler {
return result;
};

this.queuedPromise = new TPromise((c, e, p) => {
this.activePromise.then(onComplete, onComplete, p).done(c);
this.queuedPromise = new TPromise(c => {
this.activePromise.then(onComplete, onComplete).done(c);
}, () => {
this.activePromise.cancel();
});
}

return new TPromise((c, e, p) => {
this.queuedPromise.then(c, e, p);
return new TPromise((c, e) => {
this.queuedPromise.then(c, e);
}, () => {
// no-op
});
}

this.activePromise = promiseFactory();

return new TPromise((c, e, p) => {
return new TPromise((c, e) => {
this.activePromise.done((result: any) => {
this.activePromise = null;
c(result);
}, (err: any) => {
this.activePromise = null;
e(err);
}, p);
});
}, () => {
this.activePromise.cancel();
});
Expand Down Expand Up @@ -378,20 +378,18 @@ export class ShallowCancelThenPromise<T> extends TPromise<T> {
constructor(outer: TPromise<T>) {

let completeCallback: ValueCallback,
errorCallback: ErrorCallback,
progressCallback: ProgressCallback;
errorCallback: ErrorCallback;

super((c, e, p) => {
super((c, e) => {
completeCallback = c;
errorCallback = e;
progressCallback = p;
}, () => {
// cancel this promise but not the
// outer promise
errorCallback(errors.canceled());
});

outer.then(completeCallback, errorCallback, progressCallback);
outer.then(completeCallback, errorCallback);
}
}

Expand Down Expand Up @@ -425,7 +423,7 @@ export function always<T>(thenable: TPromise<T>, f: Function): TPromise<T>;
export function always<T>(promise: Thenable<T>, f: Function): Thenable<T>;
export function always<T>(winjsPromiseOrThenable: Thenable<T> | TPromise<T>, f: Function): TPromise<T> | Thenable<T> {
if (isWinJSPromise(winjsPromiseOrThenable)) {
return new TPromise<T>((c, e, p) => {
return new TPromise<T>((c, e) => {
winjsPromiseOrThenable.done((result) => {
try {
f(result);
Expand All @@ -440,8 +438,6 @@ export function always<T>(winjsPromiseOrThenable: Thenable<T> | TPromise<T>, f:
errors.onUnexpectedError(e1);
}
e(err);
}, (progress) => {
p(progress);
});
}, () => {
winjsPromiseOrThenable.cancel();
Expand Down Expand Up @@ -534,7 +530,6 @@ interface ILimitedTaskFactory {
factory: ITask<TPromise>;
c: ValueCallback;
e: ErrorCallback;
p: ProgressCallback;
}

/**
Expand Down Expand Up @@ -563,14 +558,9 @@ export class Limiter<T> {
}

queue(promiseFactory: ITask<TPromise>): TPromise;
queue(promiseFactory: ITask<TPromise<T>>): TPromise<T> {
return new TPromise<T>((c, e, p) => {
this.outstandingPromises.push({
factory: promiseFactory,
c: c,
e: e,
p: p
});
queue(factory: ITask<TPromise<T>>): TPromise<T> {
return new TPromise<T>((c, e) => {
this.outstandingPromises.push({ factory, c, e });

this.consume();
});
Expand All @@ -582,7 +572,7 @@ export class Limiter<T> {
this.runningPromises++;

const promise = iLimitedTask.factory();
promise.done(iLimitedTask.c, iLimitedTask.e, iLimitedTask.p);
promise.done(iLimitedTask.c, iLimitedTask.e);
promise.done(() => this.consumed(), () => this.consumed());
}
}
Expand Down
16 changes: 5 additions & 11 deletions src/vs/base/common/winjs.base.d.ts
Expand Up @@ -5,25 +5,21 @@
/// Interfaces for WinJS

export type ErrorCallback = (error: any) => void;
export type ProgressCallback<TProgress = any> = (progress: TProgress) => void;

export declare class Promise<T = any, TProgress = any> {
export declare class Promise<T = any> {
constructor(
executor: (
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason: any) => void,
progress: (progress: TProgress) => void) => void,
reject: (reason: any) => void) => void,
oncancel?: () => void);

public then<TResult1 = T, TResult2 = never>(
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
onprogress?: (progress: TProgress) => void): Promise<TResult1 | TResult2, TProgress>;
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;

public done(
onfulfilled?: (value: T) => void,
onrejected?: (reason: any) => void,
onprogress?: (progress: TProgress) => void): void;
onrejected?: (reason: any) => void): void;

public cancel(): void;

Expand Down Expand Up @@ -56,9 +52,7 @@ export type TValueCallback<T = any> = (value: T | PromiseLike<T>) => void;

export {
Promise as TPromise,
Promise as PPromise,
TValueCallback as ValueCallback,
ProgressCallback as TProgressCallback
TValueCallback as ValueCallback
};

export interface IPromiseErrorDetail {
Expand Down
14 changes: 3 additions & 11 deletions src/vs/base/parts/ipc/common/ipc.ts
Expand Up @@ -14,7 +14,6 @@ enum MessageType {
RequestPromiseCancel,
ResponseInitialize,
ResponsePromiseSuccess,
ResponsePromiseProgress,
ResponsePromiseError,
ResponsePromiseErrorObj,

Expand All @@ -26,7 +25,6 @@ enum MessageType {
function isResponse(messageType: MessageType): boolean {
return messageType === MessageType.ResponseInitialize
|| messageType === MessageType.ResponsePromiseSuccess
|| messageType === MessageType.ResponsePromiseProgress
|| messageType === MessageType.ResponsePromiseError
|| messageType === MessageType.ResponsePromiseErrorObj
|| messageType === MessageType.ResponseEventFire;
Expand Down Expand Up @@ -177,8 +175,6 @@ export class ChannelServer implements IChannelServer, IDisposable {
}

delete this.activeRequests[request.id];
}, data => {
this.protocol.send(<IRawResponse>{ id, data, type: MessageType.ResponsePromiseProgress });
});

this.activeRequests[request.id] = toDisposable(() => requestPromise.cancel());
Expand Down Expand Up @@ -288,7 +284,7 @@ export class ChannelClient implements IChannelClient, IDisposable {
private doRequest(request: IRequest): Promise {
const id = request.raw.id;

return new TPromise((c, e, p) => {
return new TPromise((c, e) => {
this.handlers[id] = response => {
switch (response.type) {
case MessageType.ResponsePromiseSuccess:
Expand All @@ -308,10 +304,6 @@ export class ChannelClient implements IChannelClient, IDisposable {
delete this.handlers[id];
e(response.data);
break;

case MessageType.ResponsePromiseProgress:
p(response.data);
break;
}
};

Expand All @@ -323,12 +315,12 @@ export class ChannelClient implements IChannelClient, IDisposable {
private bufferRequest(request: IRequest): Promise {
let flushedRequest: Promise = null;

return new TPromise((c, e, p) => {
return new TPromise((c, e) => {
this.bufferedRequests.push(request);

request.flush = () => {
request.flush = null;
flushedRequest = this.doRequest(request).then(c, e, p);
flushedRequest = this.doRequest(request).then(c, e);
};
}, () => {
request.flush = null;
Expand Down
5 changes: 2 additions & 3 deletions src/vs/base/parts/ipc/node/ipc.cp.ts
Expand Up @@ -107,9 +107,8 @@ export class Client implements IChannelClient, IDisposable {
const channel = this.channels[channelName] || (this.channels[channelName] = this.client.getChannel(channelName));
const request: TPromise<void> = channel.call(name, arg);

// Progress doesn't propagate across 'then', we need to create a promise wrapper
const result = new TPromise<void>((c, e, p) => {
request.then(c, e, p).done(() => {
const result = new TPromise<void>((c, e) => {
request.then(c, e).done(() => {
if (!this.activeRequests) {
return;
}
Expand Down
114 changes: 0 additions & 114 deletions src/vs/base/parts/ipc/test/node/ipc.perf.ts

This file was deleted.