socket.io
socket.io copied to clipboard
fix(socket.io): improve `close()` function
The kind of change this PR does introduce
- [x] a bug fix
- [ ] a new feature
- [ ] an update to the documentation
- [ ] a code change that improves performance
- [ ] other
Current behavior
After https://github.com/socketio/socket.io/pull/4971 the usage of the close() function has become confusing and sometimes misleading.
Since close() now returns a Promise, I would expect the httpServer to close when the promise is resolved. However, this is not the case.
await io.close();
// httpServer not closed yet
Also, in order to catch all possible errors, I need to use a mixed style of async/await and callbacks:
io.close(error => {
if (error) {
// error here
}
}).catch(error => {
// another error here
});
New behavior
await io.close();
// httpServer closed
io.close().catch(error => {
// all errors here
});
@darrachequesne could you please take a look? Thanks
I think it's good moment to deprecate the error argument here:
https://github.com/socketio/socket.io/blob/91e1c8b3584054db6072046404a24e79a17c1367/packages/socket.io/lib/index.ts#L807