debt - accept a Thenable instead of a WinJS.Promise

This commit is contained in:
Johannes Rieken 2018-08-10 10:39:44 +02:00
parent 44d764b28a
commit f6a6db18c4
3 changed files with 7 additions and 6 deletions

View file

@ -7,6 +7,7 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { isThenable } from 'vs/base/common/async';
export const ILifecycleService = createDecorator<ILifecycleService>('lifecycleService');
@ -23,7 +24,7 @@ export interface ShutdownEvent {
/**
* Allows to veto the shutdown. The veto can be a long running operation.
*/
veto(value: boolean | TPromise<boolean>): void;
veto(value: boolean | Thenable<boolean>): void;
/**
* The reason why Code is shutting down.
@ -108,12 +109,12 @@ export const NullLifecycleService: ILifecycleService = {
};
// Shared veto handling across main and renderer
export function handleVetos(vetos: (boolean | TPromise<boolean>)[], onError: (error: Error) => void): TPromise<boolean /* veto */> {
export function handleVetos(vetos: (boolean | Thenable<boolean>)[], onError: (error: Error) => void): TPromise<boolean /* veto */> {
if (vetos.length === 0) {
return TPromise.as(false);
}
const promises: TPromise<void>[] = [];
const promises: Thenable<void>[] = [];
let lazyValue = false;
for (let valueOrPromise of vetos) {
@ -123,7 +124,7 @@ export function handleVetos(vetos: (boolean | TPromise<boolean>)[], onError: (er
return TPromise.as(true);
}
if (TPromise.is(valueOrPromise)) {
if (isThenable(valueOrPromise)) {
promises.push(valueOrPromise.then(value => {
if (value) {
lazyValue = true; // veto, done

View file

@ -83,7 +83,7 @@ export class LifecycleService implements ILifecycleService {
}
private onBeforeUnload(reason: ShutdownReason): TPromise<boolean> {
const vetos: (boolean | TPromise<boolean>)[] = [];
const vetos: (boolean | Thenable<boolean>)[] = [];
this._onWillShutdown.fire({
veto(value) {

View file

@ -506,7 +506,7 @@ export class ExtensionHostProcessWorker {
}
});
event.veto(TPromise.wrap(timeout(100 /* wait a bit for IPC to get delivered */)).then(() => false));
event.veto(timeout(100 /* wait a bit for IPC to get delivered */).then(() => false));
}
}
}