mirror of
https://github.com/Microsoft/vscode
synced 2024-10-13 06:48:17 +00:00
debt - accept a Thenable instead of a WinJS.Promise
This commit is contained in:
parent
44d764b28a
commit
f6a6db18c4
|
@ -7,6 +7,7 @@
|
||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
import { Event } from 'vs/base/common/event';
|
import { Event } from 'vs/base/common/event';
|
||||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||||
|
import { isThenable } from 'vs/base/common/async';
|
||||||
|
|
||||||
export const ILifecycleService = createDecorator<ILifecycleService>('lifecycleService');
|
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.
|
* 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.
|
* The reason why Code is shutting down.
|
||||||
|
@ -108,12 +109,12 @@ export const NullLifecycleService: ILifecycleService = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Shared veto handling across main and renderer
|
// 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) {
|
if (vetos.length === 0) {
|
||||||
return TPromise.as(false);
|
return TPromise.as(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises: TPromise<void>[] = [];
|
const promises: Thenable<void>[] = [];
|
||||||
let lazyValue = false;
|
let lazyValue = false;
|
||||||
|
|
||||||
for (let valueOrPromise of vetos) {
|
for (let valueOrPromise of vetos) {
|
||||||
|
@ -123,7 +124,7 @@ export function handleVetos(vetos: (boolean | TPromise<boolean>)[], onError: (er
|
||||||
return TPromise.as(true);
|
return TPromise.as(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TPromise.is(valueOrPromise)) {
|
if (isThenable(valueOrPromise)) {
|
||||||
promises.push(valueOrPromise.then(value => {
|
promises.push(valueOrPromise.then(value => {
|
||||||
if (value) {
|
if (value) {
|
||||||
lazyValue = true; // veto, done
|
lazyValue = true; // veto, done
|
||||||
|
|
|
@ -83,7 +83,7 @@ export class LifecycleService implements ILifecycleService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onBeforeUnload(reason: ShutdownReason): TPromise<boolean> {
|
private onBeforeUnload(reason: ShutdownReason): TPromise<boolean> {
|
||||||
const vetos: (boolean | TPromise<boolean>)[] = [];
|
const vetos: (boolean | Thenable<boolean>)[] = [];
|
||||||
|
|
||||||
this._onWillShutdown.fire({
|
this._onWillShutdown.fire({
|
||||||
veto(value) {
|
veto(value) {
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue