Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing finalizers on unload/exit #8450

Open
jimmywarting opened this issue Oct 28, 2022 · 0 comments
Open

Executing finalizers on unload/exit #8450

jimmywarting opened this issue Oct 28, 2022 · 0 comments

Comments

@jimmywarting
Copy link

I wrote a NodeJS thing that would store temporary files in the temp directory and where deleted when the objects got GC'ed
but it never got deleted when the NodeJS process exits so the files remain in the temp directory.

I think it would be useful to be able to control weather or not a registered function should do the cleanup job before a process exit.
And i thought to myself as well, could browser benefit from this as well? I think so... but haven't come up with any usecases yet

i was thinking in terms of

const reg = new FinalizationRegistry(cleanup)
reg.register(obj, id, { 
  runOnUnload: true 
})

// or
const reg = new FinalizationRegistry(clear, { 
  runOnUnload: true
})

Some alternative words for it could be runOnQuit or runOnExit

The idea here is to do some cleanup when a process or when a worker also quits. NodeJS or Deno do not have a onunload event so hence the option/proposal to being able to control it with an option with finalizers...

I also know that there is this cleanup some proposal so maybe it would be possible to do something like:

process.on('exit', reg.cleanupSome)
onunload(reg.cleanupSome)

But i don't know... i fear that the functions will not have time to run... i just wanted to lift this up as there arn't any good alternative right now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant