You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It might sound strange, but I'd like some way to hook into mainFinished - kind of as a finalizer.
The Node.js runtime can block program termination with object refs. See net.Socket.ref/net.Socket.unref for example. This is useful for shutting down keep-alive connections.
I'd like to call "unref" on mainFinished to close down any sockets when all of the Go code has finished executing. I can explain in more detail if it still doesn't make sense.
package main
funcmain() {
err:=run()
iferr!=nil {
log.Println(err)
}
// Run "finalizer" code here.
}
If there's a reason that can't be done, then my next question is...
Can we use an existing API (which GopherJS doesn't yet implement) and achieve this by implementing that API? Instead of creating new/custom API that doesn't exist in real Go standard library. What about runtime.SetFinalizer?
This is also the main missing feature preventing running standard library tests in the browser (requested again here: #558 (comment) )
And to answer your question, @shurcooL, I don't think it can be done with plain go code, because, if I understand the request (and certainly for #383), it needs to be visible to the external JS environment.
This proposal seems very similar to #383, so I'm closing this issue in favor of the earlier one to avoid splitting the discussion. I've copied the text of the first comment into #383 for posterity.
It might sound strange, but I'd like some way to hook into
mainFinished
- kind of as a finalizer.The Node.js runtime can block program termination with object refs. See net.Socket.ref/net.Socket.unref for example. This is useful for shutting down keep-alive connections.
I'd like to call "unref" on mainFinished to close down any sockets when all of the Go code has finished executing. I can explain in more detail if it still doesn't make sense.
runtime.AddProgramFinalizer(func())
runtime.OnMainFinished(func())
Essentially:
The text was updated successfully, but these errors were encountered: