mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
extract _addLeakageTraceLogic
-util
This commit is contained in:
parent
447887fae9
commit
665a9c61a8
|
@ -10,8 +10,23 @@ import { combinedDisposable, Disposable, DisposableStore, IDisposable, toDisposa
|
||||||
import { LinkedList } from 'vs/base/common/linkedList';
|
import { LinkedList } from 'vs/base/common/linkedList';
|
||||||
import { StopWatch } from 'vs/base/common/stopwatch';
|
import { StopWatch } from 'vs/base/common/stopwatch';
|
||||||
|
|
||||||
let TRACE_LIKEY_SNAPSHOT_LEAKAGE = false;
|
|
||||||
// TRACE_LIKEY_SNAPSHOT_LEAKAGE = Boolean("true"); // causes an ESLint warning so that this isn't pushed by accident
|
function _addLeakageTraceLogic(options: EmitterOptions) {
|
||||||
|
let enabled = false;
|
||||||
|
// enabled = Boolean("true"); // causes an ESLint warning so that this isn't pushed by accident
|
||||||
|
if (enabled) {
|
||||||
|
const { onListenerDidAdd: origListenerDidAdd } = options;
|
||||||
|
const stack = Stacktrace.create();
|
||||||
|
let count = 0;
|
||||||
|
options.onListenerDidAdd = () => {
|
||||||
|
if (++count === 2) {
|
||||||
|
console.warn('snapshotted emitter LIKELY used public and SHOULD HAVE BEEN created with DisposableStore. snapshotted here');
|
||||||
|
stack.print();
|
||||||
|
}
|
||||||
|
origListenerDidAdd?.();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To an event a function with one or zero parameters
|
* To an event a function with one or zero parameters
|
||||||
|
@ -125,15 +140,8 @@ export namespace Event {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (TRACE_LIKEY_SNAPSHOT_LEAKAGE) {
|
if (!disposable) {
|
||||||
let stack = Stacktrace.create();
|
_addLeakageTraceLogic(options);
|
||||||
let count = 0;
|
|
||||||
options.onListenerDidAdd = () => {
|
|
||||||
if (++count === 2) {
|
|
||||||
console.warn('snapshotted emitter LIKELY used public and SHOULD HAVE BEEN created with DisposableStore. snapshotted here');
|
|
||||||
stack.print();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const emitter = new Emitter<T>(options);
|
const emitter = new Emitter<T>(options);
|
||||||
|
@ -165,7 +173,7 @@ export namespace Event {
|
||||||
let handle: any = undefined;
|
let handle: any = undefined;
|
||||||
let numDebouncedCalls = 0;
|
let numDebouncedCalls = 0;
|
||||||
|
|
||||||
const emitter = new Emitter<O>({
|
const options: EmitterOptions | undefined = {
|
||||||
leakWarningThreshold,
|
leakWarningThreshold,
|
||||||
onFirstListenerAdd() {
|
onFirstListenerAdd() {
|
||||||
subscription = event(cur => {
|
subscription = event(cur => {
|
||||||
|
@ -193,7 +201,13 @@ export namespace Event {
|
||||||
onLastListenerRemove() {
|
onLastListenerRemove() {
|
||||||
subscription.dispose();
|
subscription.dispose();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (!disposable) {
|
||||||
|
_addLeakageTraceLogic(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
const emitter = new Emitter<O>(options);
|
||||||
|
|
||||||
if (disposable) {
|
if (disposable) {
|
||||||
disposable.add(emitter);
|
disposable.add(emitter);
|
||||||
|
|
Loading…
Reference in a new issue