Skip to content

proposal: add a way to hook into mainFinished #525

@broady

Description

@broady

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:

$mainFinished = true;
for (var i = 0; i < $mainFinishers.length; i++) {
  $mainFinishers[i]();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions