Skip to content

Commit a1a0771

Browse files
committed
fix: Fix end() method on async write()
1 parent 2418cf6 commit a1a0771

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/TcpSocket.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,15 @@ export default class TcpSocket {
227227
*/
228228
end(data, encoding) {
229229
if (this._destroyed) return;
230-
if (data) this.write(data, encoding);
231-
this._destroyed = true;
232-
Sockets.end(this._id);
230+
if (data) {
231+
this.write(data, encoding, () => {
232+
this._destroyed = true;
233+
Sockets.end(this._id);
234+
});
235+
} else {
236+
this._destroyed = true;
237+
Sockets.end(this._id);
238+
}
233239
}
234240

235241
destroy() {

0 commit comments

Comments
 (0)