debt - cleanup some of async.ts
This commit is contained in:
parent
f8e67cef5d
commit
e1fbd9ce6a
4 changed files with 17 additions and 20 deletions
|
@ -8,7 +8,7 @@
|
|||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import * as errors from 'vs/base/common/errors';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ErrorCallback, TPromise, ValueCallback } from 'vs/base/common/winjs.base';
|
||||
|
||||
|
@ -345,14 +345,6 @@ export function timeout(millis: number, token?: CancellationToken): CancelablePr
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns `true` if candidate is a `WinJS.Promise`
|
||||
*/
|
||||
export function isWinJSPromise(candidate: any): candidate is TPromise {
|
||||
return isThenable(candidate) && typeof (candidate as any).done === 'function';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new promise that joins the provided promise. Upon completion of
|
||||
* the provided promise the provided function will always be called. This
|
||||
|
@ -553,17 +545,18 @@ export class ResourceQueue {
|
|||
}
|
||||
}
|
||||
|
||||
export function setDisposableTimeout(handler: Function, timeout: number, ...args: any[]): IDisposable {
|
||||
const handle = setTimeout(handler, timeout, ...args);
|
||||
return { dispose() { clearTimeout(handle); } };
|
||||
}
|
||||
|
||||
export class TimeoutTimer extends Disposable {
|
||||
private _token: number;
|
||||
|
||||
constructor() {
|
||||
constructor();
|
||||
constructor(runner: () => void, timeout: number);
|
||||
constructor(runner?: () => void, timeout?: number) {
|
||||
super();
|
||||
this._token = -1;
|
||||
|
||||
if (typeof runner === 'function' && typeof timeout === 'number') {
|
||||
this.setIfNotSet(runner, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
|
||||
import { Promise as WinJSPromise } from './winjs.base';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { isWinJSPromise } from 'vs/base/common/async';
|
||||
import { isThenable } from 'vs/base/common/async';
|
||||
|
||||
function isWinJSPromise(candidate: any): candidate is WinJSPromise {
|
||||
return isThenable(candidate) && typeof (candidate as any).done === 'function';
|
||||
}
|
||||
|
||||
/**
|
||||
* A polyfill for the native promises. The implementation is based on
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import 'vs/css!./messageController';
|
||||
import * as nls from 'vs/nls';
|
||||
import { setDisposableTimeout } from 'vs/base/common/async';
|
||||
import { TimeoutTimer } from 'vs/base/common/async';
|
||||
import { KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { alert } from 'vs/base/browser/ui/aria/aria';
|
||||
|
@ -75,7 +75,7 @@ export class MessageController extends Disposable implements editorCommon.IEdito
|
|||
this._messageListeners.push(this._editor.onDidChangeModel(() => this.closeMessage()));
|
||||
|
||||
// close after 3s
|
||||
this._messageListeners.push(setDisposableTimeout(() => this.closeMessage(), 3000));
|
||||
this._messageListeners.push(new TimeoutTimer(() => this.closeMessage(), 3000));
|
||||
|
||||
// close on mouse move
|
||||
let bounds: Range;
|
||||
|
|
|
@ -13,7 +13,7 @@ import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
|
|||
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
|
||||
import { Action, IAction, RadioGroup } from 'vs/base/common/actions';
|
||||
import { firstIndex } from 'vs/base/common/arrays';
|
||||
import { createCancelablePromise, setDisposableTimeout } from 'vs/base/common/async';
|
||||
import { createCancelablePromise, TimeoutTimer } from 'vs/base/common/async';
|
||||
import { isPromiseCanceledError, onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { defaultGenerator } from 'vs/base/common/idGenerator';
|
||||
|
@ -469,7 +469,7 @@ export class OutlinePanel extends ViewletPanel {
|
|||
let loadingMessage: IDisposable;
|
||||
let oldModel = <OutlineModel>this._tree.getInput();
|
||||
if (!oldModel) {
|
||||
loadingMessage = setDisposableTimeout(
|
||||
loadingMessage = new TimeoutTimer(
|
||||
() => this._showMessage(localize('loading', "Loading document symbols for '{0}'...", posix.basename(textModel.uri.path))),
|
||||
100
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue