Skip to content

Commit

Permalink
Use a WeakRef to store the resource
Browse files Browse the repository at this point in the history
Closes mafintosh#84

Signed-off-by: Jon Koops <jonkoops@gmail.com>
  • Loading branch information
jonkoops committed Dec 15, 2024
1 parent 01906a9 commit 3488466
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const hook = createHook({

asyncResources.set(asyncId, {
type,
resource,
resourceRef: new WeakRef(resource),
stacks
})
},
Expand All @@ -36,7 +36,15 @@ export default function whyIsNodeRunning (logger = console) {
hook.disable()

const activeAsyncResources = Array.from(asyncResources.values())
.filter(({ resource }) => resource.hasRef?.() ?? true)
.filter(({ resourceRef }) => {
const resource = resourceRef.deref();

if (resource === undefined) {
return false;
}

return resource.hasRef?.() ?? true;
});

logger.error(`There are ${activeAsyncResources.length} handle(s) keeping the process running.`)

Expand Down

0 comments on commit 3488466

Please sign in to comment.