Skip to content

Commit 6f828b8

Browse files
docs: say what close() and end() do with messages already sent (#1306)
close() maps to the close() syscall, so anything still queued by send() is not delivered; end() delivers it and then sends the close message. The distinction was implied by 'forcefully' and 'gracefully' but never written, and reading close() as the graceful one costs a silent loss of the last message.
1 parent f0324e9 commit 6f828b8

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎docs/index.d.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ export interface WebSocket<UserData> {
6868
getBufferedAmount() : number;
6969

7070
/** Gracefully closes this WebSocket. Immediately calls the close handler.
71-
* A WebSocket close message is sent with code and shortMessage.
71+
* A WebSocket close message is sent with code and shortMessage, and
72+
* messages already passed to send() are delivered before the close.
7273
*/
7374
end(code?: number, shortMessage?: RecognizedString) : void;
7475

7576
/** Forcefully closes this WebSocket. Immediately calls the close handler.
76-
* No WebSocket close message is sent.
77+
* No WebSocket close message is sent. This maps to the close() syscall and
78+
* inherits its effects, so messages already passed to send() are not
79+
* delivered; use end() to send a last message before closing.
7780
*/
7881
close() : void;
7982

0 commit comments

Comments
 (0)