-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Implement Symbol.dispose
/ Symbol.asyncDispose
for Deno namespace APIs
#20839
Comments
Ok, open question answered: the dispose methods should not throw if called more than once. This means:
|
After some offline discussion, I retract the throwing |
|
ah the above returns a string, so it would be a breaking change to modify them |
|
This commit implements Symbol.dispose and Symbol.asyncDispose for the relevant resources. Closes #20839 --------- Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
I've started thinking about how to integrate explicit resource management into Deno APIs. Here is my proposal so far.
Deno.FsFile
: implementSymbol.dispose
that internally callsfile.close()
, implementSymbol.asyncDispose
to just throwDeno.FsWatcher
: implementSymbol.dispose
that internally callsfsWatcher.close()
, implementSymbol.asyncDispose
to just throwDeno.HttpConn
: implementSymbol.dispose
that internally callshttpConn.close()
, implementSymbol.asyncDispose
to just throwDeno.Server
: implementSymbol.asyncDispose
to callawait server.shutdown()
. do not implementSymbol.dispose
Deno.stdin
/Deno.stderr
/Deno.stdout
: do not implement disposal methodsDeno.Conn
: implementSymbol.dispose
that internally callsconn.close()
, implementSymbol.asyncDispose
to just throwDeno.Listener
: implementSymbol.dispose
that internally callslistener.close()
, implementSymbol.asyncDispose
to just throwDeno.Process
: deprecated, do nothingDeno.ChildProcess
: implementSymbol.asyncDispose
that internally callscp.kill()
, thenawait cp.status
Deno.Kv
: implementSymbol.dispose
that internally callskv.close()
, implementSymbol.asyncDispose
to just throwAdditionally, we may want to update all of our
.unref()
methods on resources to return an object with a[Symbol.dispose]
method that calls.ref()
on the resource (and vice versa).There is an open question about whether these close methods should be idempotant (not throw if the resource is already closed), or whether it should throw. I am leaning towards them not throwing. This is especially important for resources that may well close through external means, like
Deno.ChildProcess
. I've asked @rbuckton for guidance on this: tc39/proposal-explicit-resource-management#207The text was updated successfully, but these errors were encountered: