Skip to content

Conversation

everett1992
Copy link
Contributor

@everett1992 everett1992 commented Aug 28, 2025

Add method to close transport and writer.

Before there was no public way to close the transport/reader/writer created by attach for a socket, and the connection would hold the node process open.

For example, this script would not exit (without an explicit process.exit(0))

attach({ socket: pathToNvimSocket })

This change adds .close to transport and NeovimClient which ends the writer. The other side of the connection should then close the reader which triggers detach and the cleanup code.

I added asyncDispose methods for folks using modern javascript runtimes that support explicit resource management:

await using client = attach({ socket: pathToNvimSocket })

Other wise you can call close

try {
  const client = attach({ socket: pathToNvimSocket })
} finally {
  await client.close()
}

fix #481

Add method to close transport and writer.

Before there was no public way to close the transport/reader/writer created by attach
for a socket, and the connection would hold the node process open.

For example, this script would not exit (without an explicit process.exit(0))
```
attach({ socket: pathToNvimSocket })
```

This change adds .close to transport and NeovimClient which ends the writer.
The other side of the connection should then close the reader which triggers detach and the
cleanup code.

I added asyncDispose methods for folks using modern javascript runtimes that support explicit
resource management:

```
await using client = attach({ socket: pathToNvimSocket })
```

Other wise you can call close
```
try {
  const client = attach({ socket: pathToNvimSocket })
} finally {
  await client.close()
}
```
Comment on lines -91 to 93
this.reader.on('end', () => {
this.reader.once('end', () => {
this.emit('detach');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice change, I wonder if this will fix some test flakiness that happens sometimes

@@ -249,4 +250,15 @@ export class NeovimClient extends Neovim {

return false;
}

async close(): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justinmk
Copy link
Member

justinmk commented Sep 1, 2025

This is a nice change, thanks!

Included in the 5.4.0 release: https://www.npmjs.com/package/neovim

@justinmk justinmk merged commit edb3186 into neovim:master Sep 1, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Public method to close a client?
2 participants