diff --git a/src/vs/workbench/services/extensions/node/ipcRemoteCom.ts b/src/vs/workbench/services/extensions/node/ipcRemoteCom.ts index 41ca7dcb99350..3e9db497fbe41 100644 --- a/src/vs/workbench/services/extensions/node/ipcRemoteCom.ts +++ b/src/vs/workbench/services/extensions/node/ipcRemoteCom.ts @@ -8,6 +8,7 @@ import winjs = require('vs/base/common/winjs.base'); import marshalling = require('vs/base/common/marshalling'); import errors = require('vs/base/common/errors'); import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc'; +import { LazyPromise } from "vs/workbench/services/extensions/node/lazyPromise"; interface IRPCFunc { (rpcId: string, method: string, args: any[]): winjs.TPromise; @@ -40,109 +41,6 @@ class MessageFactory { } } -class LazyPromise { - - private _onCancel: () => void; - - private _actual: winjs.TPromise; - private _actualOk: winjs.ValueCallback; - private _actualErr: winjs.ErrorCallback; - - private _hasValue: boolean; - private _value: any; - - private _hasErr: boolean; - private _err: any; - - private _isCanceled: boolean; - - constructor(onCancel: () => void) { - this._onCancel = onCancel; - this._actual = null; - this._actualOk = null; - this._actualErr = null; - this._hasValue = false; - this._value = null; - this._hasErr = false; - this._err = null; - this._isCanceled = false; - } - - private _ensureActual(): winjs.TPromise { - if (!this._actual) { - this._actual = new winjs.TPromise((c, e) => { - this._actualOk = c; - this._actualErr = e; - }, this._onCancel); - - if (this._hasValue) { - this._actualOk(this._value); - } - - if (this._hasErr) { - this._actualErr(this._err); - } - } - return this._actual; - } - - public resolveOk(value: any): void { - if (this._isCanceled || this._hasErr) { - return; - } - - this._hasValue = true; - this._value = value; - - if (this._actual) { - this._actualOk(value); - } - } - - public resolveErr(err: any): void { - if (this._isCanceled || this._hasValue) { - return; - } - - this._hasErr = true; - this._err = err; - - if (this._actual) { - this._actualErr(err); - } - } - - public then(success: any, error: any): any { - if (this._isCanceled) { - return; - } - - return this._ensureActual().then(success, error); - } - - public done(success: any, error: any): void { - if (this._isCanceled) { - return; - } - - this._ensureActual().done(success, error); - } - - public cancel(): void { - if (this._hasValue || this._hasErr) { - return; - } - - this._isCanceled = true; - - if (this._actual) { - this._actual.cancel(); - } else { - this._onCancel(); - } - } -} - function createRPC(serializeAndSend: (value: string) => void): IRPCFunc { return function rpc(rpcId: string, method: string, args: any[]): winjs.TPromise { diff --git a/src/vs/workbench/services/extensions/node/lazyPromise.ts b/src/vs/workbench/services/extensions/node/lazyPromise.ts new file mode 100644 index 0000000000000..c70b58ce0bebf --- /dev/null +++ b/src/vs/workbench/services/extensions/node/lazyPromise.ts @@ -0,0 +1,110 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { TPromise, ValueCallback, ErrorCallback } from 'vs/base/common/winjs.base'; + +export class LazyPromise { + + private _onCancel: () => void; + + private _actual: TPromise; + private _actualOk: ValueCallback; + private _actualErr: ErrorCallback; + + private _hasValue: boolean; + private _value: any; + + private _hasErr: boolean; + private _err: any; + + private _isCanceled: boolean; + + constructor(onCancel: () => void) { + this._onCancel = onCancel; + this._actual = null; + this._actualOk = null; + this._actualErr = null; + this._hasValue = false; + this._value = null; + this._hasErr = false; + this._err = null; + this._isCanceled = false; + } + + private _ensureActual(): TPromise { + if (!this._actual) { + this._actual = new TPromise((c, e) => { + this._actualOk = c; + this._actualErr = e; + }, this._onCancel); + + if (this._hasValue) { + this._actualOk(this._value); + } + + if (this._hasErr) { + this._actualErr(this._err); + } + } + return this._actual; + } + + public resolveOk(value: any): void { + if (this._isCanceled || this._hasErr) { + return; + } + + this._hasValue = true; + this._value = value; + + if (this._actual) { + this._actualOk(value); + } + } + + public resolveErr(err: any): void { + if (this._isCanceled || this._hasValue) { + return; + } + + this._hasErr = true; + this._err = err; + + if (this._actual) { + this._actualErr(err); + } + } + + public then(success: any, error: any): any { + if (this._isCanceled) { + return; + } + + return this._ensureActual().then(success, error); + } + + public done(success: any, error: any): void { + if (this._isCanceled) { + return; + } + + this._ensureActual().done(success, error); + } + + public cancel(): void { + if (this._hasValue || this._hasErr) { + return; + } + + this._isCanceled = true; + + if (this._actual) { + this._actual.cancel(); + } else { + this._onCancel(); + } + } +}