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

Update Promise definition #30268

Merged
merged 5 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions build/monaco/monaco.d.ts.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@

declare module monaco {

interface Thenable<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
}
type Thenable<T> = PromiseLike<T>;

export interface IDisposable {
dispose(): void;
Expand All @@ -41,7 +32,7 @@ declare module monaco {
Error = 3,
}

#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, Promise
#include(vs/base/common/cancellation): CancellationTokenSource, CancellationToken
#include(vs/base/common/uri): URI
#include(vs/editor/common/standalone/standaloneBase): KeyCode, KeyMod
Expand Down
12 changes: 6 additions & 6 deletions src/vs/base/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,24 @@ export function setUnexpectedErrorHandler(newUnexpectedErrorHandler: (e: any) =>
errorHandler.setUnexpectedErrorHandler(newUnexpectedErrorHandler);
}

export function onUnexpectedError(e: any): void {

export function onUnexpectedError(e: any): undefined {
// ignore errors from cancelled promises
if (!isPromiseCanceledError(e)) {
errorHandler.onUnexpectedError(e);
}
return undefined;
}

export function onUnexpectedExternalError(e: any): void {

export function onUnexpectedExternalError(e: any): undefined {
// ignore errors from cancelled promises
if (!isPromiseCanceledError(e)) {
errorHandler.onUnexpectedExternalError(e);
}
return undefined;
}

export function onUnexpectedPromiseError<T>(promise: TPromise<T>): TPromise<T> {
return promise.then<T>(null, onUnexpectedError);
export function onUnexpectedPromiseError<T>(promise: TPromise<T>): TPromise<T | void> {
return promise.then(null, onUnexpectedError);
}

export function transformErrorForSerialization(error: any): any {
Expand Down
159 changes: 47 additions & 112 deletions src/vs/base/common/winjs.base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,136 +4,71 @@
*--------------------------------------------------------------------------------------------*/
/// Interfaces for WinJS

export interface ValueCallback {
(value: any): any;
}

export interface EventCallback {
(value: any): void;
}
export type ErrorCallback = (error: any) => void;
export type ProgressCallback<TProgress = any> = (progress: TProgress) => void;

export declare class Promise<T = any, TProgress = any> {
constructor(
executor: (
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason: any) => void,
progress: (progress: TProgress) => 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>;

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

export interface ErrorCallback {
(error: any): any;
}
public cancel(): void;

export interface ProgressCallback {
(progress: any): any;
}
public static as(value: null): Promise<null>;
public static as(value: undefined): Promise<undefined>;
public static as<T, TPromise extends PromiseLike<T>>(value: TPromise): TPromise;
public static as<T>(value: T): Promise<T>;

export declare class Promise {
// commented out because this conflicts with the native promise
// constructor(init: (complete: ValueCallback, error: ErrorCallback, progress: ProgressCallback) => void, oncancel?: any);
public static is(value: any): value is PromiseLike<any>;

// commented out to speed up adoption of TPromise
// static as(value:any):Promise;
public static timeout(delay: number): Promise<void>;

// static join(promises: { [name: string]: Promise; }): Promise;
static join(promises: Promise[]): Promise;
// static any(promises: Promise[]): Promise;
public static join<T1, T2>(promises: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
public static join<T>(promises: (T | PromiseLike<T>)[]): Promise<T[]>;
public static join<T>(promises: { [n: string]: T | PromiseLike<T> }): Promise<{ [n: string]: T }>;

// commented out to speed up adoption of TPromise
// static timeout(delay:number):Promise;
public static any<T>(promises: (T | PromiseLike<T>)[]): Promise<{ key: string; value: Promise<T>; }>;

// static wrapError(error: Error): Promise;
// static is(value: any): value is Thenable<any>;
// static addEventListener(type: string, fn: EventCallback): void;
public static wrap<T>(value: T | PromiseLike<T>): Promise<T>;

public then(success?: ValueCallback, error?: ErrorCallback, progress?: ProgressCallback): Promise;
// public then<U>(success?: ValueCallback, error?: ErrorCallback, progress?: ProgressCallback): TPromise<U>;
public done(success?: ValueCallback, error?: ErrorCallback, progress?: ProgressCallback): void;
public cancel(): void;
}
public static wrapError<T = never>(error: Error): Promise<T>;

/**
* The value callback to complete a promise
*/
export interface TValueCallback<T> {
(value: T | Thenable<T>): void;
/**
* @internal
*/
public static addEventListener(event: 'error', promiseErrorHandler: (e: IPromiseError) => void);
}

export type TValueCallback<T = any> = (value: T | PromiseLike<T>) => void;

export interface TProgressCallback<T> {
(progress: T): void;
}
export {
Promise as TPromise,
Promise as PPromise,
TValueCallback as ValueCallback,
ProgressCallback as TProgressCallback
};

interface IPromiseErrorDetail {
parent: TPromise<any>;
export interface IPromiseErrorDetail {
parent: Promise;
error: any;
id: number;
handler: Function;
exception: Error;
}

interface IPromiseError {
export interface IPromiseError {
detail: IPromiseErrorDetail;
}

/**
* A Promise implementation that supports progress and cancelation.
*/
export declare class TPromise<V> {

constructor(init: (complete: TValueCallback<V>, error: (err: any) => void, progress: ProgressCallback) => void, oncancel?: any);

public then<U>(success?: (value: V) => TPromise<U>, error?: (err: any) => TPromise<U>, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => TPromise<U>, error?: (err: any) => TPromise<U> | U, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => TPromise<U>, error?: (err: any) => U, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => TPromise<U>, error?: (err: any) => void, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => TPromise<U> | U, error?: (err: any) => TPromise<U>, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => TPromise<U> | U, error?: (err: any) => TPromise<U> | U, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => TPromise<U> | U, error?: (err: any) => U, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => TPromise<U> | U, error?: (err: any) => void, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => U, error?: (err: any) => TPromise<U>, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => U, error?: (err: any) => TPromise<U> | U, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => U, error?: (err: any) => U, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => U, error?: (err: any) => void, progress?: ProgressCallback): TPromise<U>;

public done(success?: (value: V) => void, error?: (err: any) => any, progress?: ProgressCallback): void;
public cancel(): void;

public static as(value: null): TPromise<null>;
public static as(value: undefined): TPromise<undefined>;
public static as<ValueType>(value: TPromise<ValueType>): TPromise<ValueType>;
public static as<ValueType>(value: Thenable<ValueType>): Thenable<ValueType>;
public static as<ValueType>(value: ValueType): TPromise<ValueType>;

public static is(value: any): value is Thenable<any>;
public static timeout(delay: number): TPromise<void>;
public static join<ValueType>(promises: TPromise<ValueType>[]): TPromise<ValueType[]>;
public static join<ValueType>(promises: Thenable<ValueType>[]): Thenable<ValueType[]>;
public static join<ValueType>(promises: { [n: string]: TPromise<ValueType> }): TPromise<{ [n: string]: ValueType }>;
public static any<ValueType>(promises: TPromise<ValueType>[]): TPromise<{ key: string; value: TPromise<ValueType>; }>;

public static wrap<ValueType>(value: Thenable<ValueType>): TPromise<ValueType>;
public static wrap<ValueType>(value: ValueType): TPromise<ValueType>;

public static wrapError<ValueType>(error: Error): TPromise<ValueType>;

/**
* @internal
*/
public static addEventListener(event: 'error', promiseErrorHandler: (e: IPromiseError) => void);
}

// --- Generic promise with generic progress value
export declare class PPromise<C, P> extends TPromise<C> {

constructor(init: (complete: TValueCallback<C>, error: (err: any) => void, progress: TProgressCallback<P>) => void, oncancel?: any);

public then<U>(success?: (value: C) => PPromise<U, P>, error?: (err: any) => PPromise<U, P>, progress?: (value: P) => void): PPromise<U, P>;
public then<U>(success?: (value: C) => PPromise<U, P>, error?: (err: any) => U, progress?: (value: P) => void): PPromise<U, P>;
public then<U>(success?: (value: C) => PPromise<U, P>, error?: (err: any) => void, progress?: (value: P) => void): PPromise<U, P>;
public then<U>(success?: (value: C) => U, error?: (err: any) => PPromise<C, P>, progress?: (value: P) => void): PPromise<U, P>;
public then<U>(success?: (value: C) => U, error?: (err: any) => U, progress?: (value: P) => void): PPromise<U, P>;
public then<U>(success?: (value: C) => U, error?: (err: any) => void, progress?: (value: P) => void): PPromise<U, P>;

public done(success?: (value: C) => void, error?: (err: any) => any, progress?: (value: P) => void): void;
public cancel(): void;

public static as<V>(value: V): TPromise<V>;
public static timeout(delay: number): PPromise<void, void>;
public static join<C, P>(promises: PPromise<C, P>[]): PPromise<C, P[]>;
public static join<C, P>(promises: { [n: string]: PPromise<C, P> }): PPromise<{ [n: string]: C }, P>;
public static any<C, P>(promises: PPromise<C, P>[]): PPromise<{ key: string; value: PPromise<C, P>; }, P>;
public static wrapError<V>(error: Error): TPromise<V>;
}
2 changes: 1 addition & 1 deletion src/vs/code/electron-browser/sharedProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function main(server: Server, initData: ISharedProcessInitData): void {

function setupIPC(hook: string): TPromise<Server> {
function setup(retry: boolean): TPromise<Server> {
return serve(hook).then<Server>(null, err => {
return serve(hook).then(null, err => {
if (!retry || platform.isWindows || err.code !== 'EADDRINUSE') {
return TPromise.wrapError(err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ function getDefinitions<T>(
const promises = provider.map((provider, idx) => {
return asWinJsPromise((token) => {
return provide(provider, model, position, token);
}).then(result => {
return result;
}, err => {
}).then(undefined, err => {
onUnexpectedExternalError(err);
return null;
});
});
return outputResults(promises);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export class DefinitionAction extends EditorAction {
}, (err) => {
// report an error
messageService.show(Severity.Error, err);
return false;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/hover/browser/hoverOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class HoverOperation<Result> {
this._asyncComputationPromise = this._computer.computeAsync().then((asyncResult: Result) => {
this._asyncComputationPromiseDone = true;
this._withAsyncResult(asyncResult);
}, () => this._onError);
}, (e) => this._onError(e));
} else {
this._asyncComputationPromiseDone = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class ParameterHintsModel extends Disposable {

private doTrigger(): void {
provideSignatureHelp(this.editor.getModel(), this.editor.getPosition())
.then<SignatureHelp>(null, onUnexpectedError)
.then(null, onUnexpectedError)
.then(result => {
if (!result || !result.signatures || result.signatures.length === 0) {
this.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function getOccurrencesAtPosition(model: editorCommon.IReadOnlyModel, pos
return undefined;
}, err => {
onUnexpectedExternalError(err);
return undefined;
});
}
return undefined;
Expand Down
Loading