summaryrefslogtreecommitdiff
path: root/std/ws/mod.ts
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2020-02-29 01:17:00 +0900
committerGitHub <noreply@github.com>2020-02-28 11:17:00 -0500
commit9075daa2e3cfac0cdb13f5d926e39d42890982d5 (patch)
treeb53dc63bcd89ef5a4138785aa539d608ca9a0664 /std/ws/mod.ts
parent0eb91c5591eb7e5e419aa9dbdaff99f5bd8015da (diff)
[std/ws] provide default close code for ws.close() (#4172)
Diffstat (limited to 'std/ws/mod.ts')
-rw-r--r--std/ws/mod.ts7
1 files changed, 5 insertions, 2 deletions
diff --git a/std/ws/mod.ts b/std/ws/mod.ts
index 7a6e14a13..4a103ab79 100644
--- a/std/ws/mod.ts
+++ b/std/ws/mod.ts
@@ -103,9 +103,12 @@ export interface WebSocket {
/** Close connection after sending close frame to peer.
* This is canonical way of disconnection but it may hang because of peer's response delay.
+ * Default close code is 1000 (Normal Closure)
* @throws SocketClosedError
*/
- close(code: number, reason?: string): Promise<void>;
+ close(): Promise<void>;
+ close(code: number): Promise<void>;
+ close(code: number, reason: string): Promise<void>;
/** Close connection forcely without sending close frame to peer.
* This is basically undesirable way of disconnection. Use carefully. */
@@ -355,7 +358,7 @@ class WebSocketImpl implements WebSocket {
return this._isClosed;
}
- async close(code: number, reason?: string): Promise<void> {
+ async close(code = 1000, reason?: string): Promise<void> {
try {
const header = [code >>> 8, code & 0x00ff];
let payload: Uint8Array;