sandbox - remove setImmediate
and nextTick
(#133173)
This commit is contained in:
parent
075ba020e8
commit
2c458e1ccd
|
@ -254,7 +254,7 @@ export function topAsync<T>(array: T[], compare: (a: T, b: T) => number, n: numb
|
|||
const result = array.slice(0, n).sort(compare);
|
||||
for (let i = n, m = Math.min(n + batch, o); i < o; i = m, m = Math.min(m + batch, o)) {
|
||||
if (i > n) {
|
||||
await new Promise(resolve => setTimeout(resolve)); // nextTick() would starve I/O.
|
||||
await new Promise(resolve => setTimeout(resolve)); // any other delay function would starve I/O
|
||||
}
|
||||
if (token && token.isCancellationRequested) {
|
||||
throw canceled();
|
||||
|
|
|
@ -198,7 +198,7 @@ export namespace Event {
|
|||
/**
|
||||
* @deprecated DO NOT use, this leaks memory
|
||||
*/
|
||||
export function buffer<T>(event: Event<T>, nextTick = false, _buffer: T[] = []): Event<T> {
|
||||
export function buffer<T>(event: Event<T>, flushAfterTimeout = false, _buffer: T[] = []): Event<T> {
|
||||
let buffer: T[] | null = _buffer.slice();
|
||||
|
||||
let listener: IDisposable | null = event(e => {
|
||||
|
@ -225,7 +225,7 @@ export namespace Event {
|
|||
|
||||
onFirstListenerDidAdd() {
|
||||
if (buffer) {
|
||||
if (nextTick) {
|
||||
if (flushAfterTimeout) {
|
||||
setTimeout(flush);
|
||||
} else {
|
||||
flush();
|
||||
|
|
|
@ -38,7 +38,6 @@ export interface INodeProcess {
|
|||
platform: string;
|
||||
arch: string;
|
||||
env: IProcessEnvironment;
|
||||
nextTick?: (callback: (...args: any[]) => void) => void;
|
||||
versions?: {
|
||||
electron?: string;
|
||||
};
|
||||
|
@ -186,10 +185,6 @@ export const locale = _locale;
|
|||
*/
|
||||
export const translationsConfigFile = _translationsConfigFile;
|
||||
|
||||
interface ISetImmediate {
|
||||
(callback: (...args: unknown[]) => void): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#:~:text=than%204%2C%20then-,set%20timeout%20to%204,-.
|
||||
*
|
||||
|
@ -228,20 +223,6 @@ export const setTimeout0 = (() => {
|
|||
return (callback: () => void) => setTimeout(callback);
|
||||
})();
|
||||
|
||||
export const setImmediate: ISetImmediate = (function defineSetImmediate() {
|
||||
if (globals.setImmediate) {
|
||||
return globals.setImmediate.bind(globals);
|
||||
}
|
||||
if (typeof globals.postMessage === 'function' && !globals.importScripts) {
|
||||
return setTimeout0;
|
||||
}
|
||||
if (typeof nodeProcess?.nextTick === 'function') {
|
||||
return nodeProcess.nextTick.bind(nodeProcess);
|
||||
}
|
||||
const _promise = Promise.resolve();
|
||||
return (callback: (...args: unknown[]) => void) => _promise.then(callback);
|
||||
})();
|
||||
|
||||
export const enum OperatingSystem {
|
||||
Windows = 1,
|
||||
Macintosh = 2,
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { globals, INodeProcess, isMacintosh, isWindows, setImmediate } from 'vs/base/common/platform';
|
||||
import { globals, INodeProcess, isMacintosh, isWindows } from 'vs/base/common/platform';
|
||||
|
||||
let safeProcess: Omit<INodeProcess, 'arch'> & { nextTick: (callback: (...args: any[]) => void) => void; arch: string | undefined; };
|
||||
let safeProcess: Omit<INodeProcess, 'arch'> & { arch: string | undefined; };
|
||||
declare const process: INodeProcess;
|
||||
|
||||
// Native sandbox environment
|
||||
|
@ -15,8 +15,7 @@ if (typeof globals.vscode !== 'undefined' && typeof globals.vscode.process !== '
|
|||
get platform() { return sandboxProcess.platform; },
|
||||
get arch() { return sandboxProcess.arch; },
|
||||
get env() { return sandboxProcess.env; },
|
||||
cwd() { return sandboxProcess.cwd(); },
|
||||
nextTick(callback: (...args: any[]) => void): void { return setImmediate(callback); }
|
||||
cwd() { return sandboxProcess.cwd(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -26,8 +25,7 @@ else if (typeof process !== 'undefined') {
|
|||
get platform() { return process.platform; },
|
||||
get arch() { return process.arch; },
|
||||
get env() { return process.env; },
|
||||
cwd() { return process.env['VSCODE_CWD'] || process.cwd(); },
|
||||
nextTick(callback: (...args: any[]) => void): void { return process.nextTick!(callback); }
|
||||
cwd() { return process.env['VSCODE_CWD'] || process.cwd(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -38,7 +36,6 @@ else {
|
|||
// Supported
|
||||
get platform() { return isWindows ? 'win32' : isMacintosh ? 'darwin' : 'linux'; },
|
||||
get arch() { return undefined; /* arch is undefined in web */ },
|
||||
nextTick(callback: (...args: any[]) => void): void { return setImmediate(callback); },
|
||||
|
||||
// Unsupported
|
||||
get env() { return {}; },
|
||||
|
@ -68,12 +65,6 @@ export const env = safeProcess.env;
|
|||
*/
|
||||
export const platform = safeProcess.platform;
|
||||
|
||||
/**
|
||||
* Provides safe access to the `nextTick` method in node.js, sandboxed or web
|
||||
* environments.
|
||||
*/
|
||||
export const nextTick = safeProcess.nextTick;
|
||||
|
||||
/**
|
||||
* Provides safe access to the `arch` method in node.js, sandboxed or web
|
||||
* environments.
|
||||
|
|
|
@ -481,7 +481,7 @@ export class BufferedEmitter<T> {
|
|||
this._hasListeners = true;
|
||||
// it is important to deliver these messages after this call, but before
|
||||
// other messages have a chance to be received (to guarantee in order delivery)
|
||||
// that's why we're using here nextTick and not other types of timeouts
|
||||
// that's why we're using here queueMicrotask and not other types of timeouts
|
||||
queueMicrotask(() => this._deliverMessages());
|
||||
},
|
||||
onLastListenerRemove: () => {
|
||||
|
|
Loading…
Reference in a new issue