fix: on write and end, log errors if we are trying to use a closed socket
This commit is contained in:
parent
7eabf6a05d
commit
57efedd0af
13
src/index.ts
13
src/index.ts
|
@ -229,15 +229,24 @@ export class Socket extends Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
write(message: string | Buffer): void {
|
write(message: string | Buffer): void {
|
||||||
|
this.callModule("socketExists", { id: this.id }).then(
|
||||||
|
([exists]: ErrTuple) => {
|
||||||
|
if (!exists) {
|
||||||
|
logErr("tried to write to closed socket");
|
||||||
|
}
|
||||||
|
this.callModule("socketWrite", { id: this.id, message });
|
||||||
|
},
|
||||||
|
);
|
||||||
this.callModule("socketWrite", { id: this.id, message });
|
this.callModule("socketWrite", { id: this.id, message });
|
||||||
}
|
}
|
||||||
|
|
||||||
end(): void {
|
end(): void {
|
||||||
this.callModule("socketExists", { id: this.id }).then(
|
this.callModule("socketExists", { id: this.id }).then(
|
||||||
([exists]: ErrTuple) => {
|
([exists]: ErrTuple) => {
|
||||||
if (exists) {
|
if (!exists) {
|
||||||
this.callModule("socketClose", { id: this.id });
|
logErr("tried to close a closed socket");
|
||||||
}
|
}
|
||||||
|
this.callModule("socketClose", { id: this.id });
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue