on-exit-leak-free
Advanced tools
Comparing version 2.1.1 to 2.1.2
16
index.js
@@ -11,4 +11,11 @@ 'use strict' | ||
} | ||
const registry = new FinalizationRegistry(clear) | ||
let registry | ||
function ensureRegistry () { | ||
if (registry === undefined) { | ||
registry = new FinalizationRegistry(clear) | ||
} | ||
} | ||
function install (event) { | ||
@@ -27,2 +34,5 @@ if (refs[event].length > 0) { | ||
process.removeListener(event, functions[event]) | ||
if (refs.exit.length === 0 && refs.beforeExit.length === 0) { | ||
registry = undefined | ||
} | ||
} | ||
@@ -69,2 +79,3 @@ | ||
ensureRegistry() | ||
registry.register(obj, ref) | ||
@@ -83,2 +94,5 @@ refs[event].push(ref) | ||
function unregister (obj) { | ||
if (registry === undefined) { | ||
return | ||
} | ||
registry.unregister(obj) | ||
@@ -85,0 +99,0 @@ for (const event of ['exit', 'beforeExit']) { |
{ | ||
"name": "on-exit-leak-free", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Execute a function on exit without leaking memory, allowing all objects to be garbage collected", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,3 +14,2 @@ 'use strict' | ||
function shutdown (obj, event) { | ||
console.log(event) | ||
shutdownCalled = true | ||
@@ -17,0 +16,0 @@ if (event === 'beforeExit') { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9246
214