summaryrefslogtreecommitdiff
path: root/ext/websocket/02_websocketstream.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-05-01 17:40:00 +0200
committerGitHub <noreply@github.com>2023-05-01 17:40:00 +0200
commitdcf391ffed3850f9026d88b146e156375c4619d4 (patch)
tree2134755e8abbecaba1d42703fe727ae701ee390c /ext/websocket/02_websocketstream.js
parent6728ad4203d731e555dabf89ec6157f113454ce6 (diff)
refactor: migrate async ops to generated wrappers (#18937)
Migrates some of existing async ops to generated wrappers introduced in https://github.com/denoland/deno/pull/18887. As a result "core.opAsync2" was removed. I will follow up with more PRs that migrate all the async ops to generated wrappers.
Diffstat (limited to 'ext/websocket/02_websocketstream.js')
-rw-r--r--ext/websocket/02_websocketstream.js35
1 files changed, 21 insertions, 14 deletions
diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js
index 06f4b50d9..2c5df262a 100644
--- a/ext/websocket/02_websocketstream.js
+++ b/ext/websocket/02_websocketstream.js
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+// deno-lint-ignore-file camelcase
/// <reference path="../../core/internal.d.ts" />
const core = globalThis.Deno.core;
@@ -32,6 +33,19 @@ const {
TypedArrayPrototypeGetByteLength,
Uint8ArrayPrototype,
} = primordials;
+const {
+ op_ws_send_text,
+ op_ws_send_binary,
+ op_ws_next_event,
+ op_ws_create,
+ op_ws_close,
+} = core.generateAsyncOpHandler(
+ "op_ws_send_text",
+ "op_ws_send_binary",
+ "op_ws_next_event",
+ "op_ws_create",
+ "op_ws_close",
+);
webidl.converters.WebSocketStreamOptions = webidl.createDictionaryConverter(
"WebSocketStreamOptions",
@@ -153,8 +167,7 @@ class WebSocketStream {
};
options.signal?.[add](abort);
PromisePrototypeThen(
- core.opAsync(
- "op_ws_create",
+ op_ws_create(
"new WebSocketStream()",
this[_url],
options.protocols ? ArrayPrototypeJoin(options.protocols, ", ") : "",
@@ -165,15 +178,12 @@ class WebSocketStream {
options.signal?.[remove](abort);
if (this[_earlyClose]) {
PromisePrototypeThen(
- core.opAsync("op_ws_close", create.rid),
+ op_ws_close(create.rid),
() => {
PromisePrototypeThen(
(async () => {
while (true) {
- const { 0: kind } = await core.opAsync(
- "op_ws_next_event",
- create.rid,
- );
+ const { 0: kind } = await op_ws_next_event(create.rid);
if (kind > 5) {
/* close */
@@ -206,11 +216,11 @@ class WebSocketStream {
const writable = new WritableStream({
write: async (chunk) => {
if (typeof chunk === "string") {
- await core.opAsync2("op_ws_send_text", this[_rid], chunk);
+ await op_ws_send_text(this[_rid], chunk);
} else if (
ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, chunk)
) {
- await core.opAsync2("op_ws_send_binary", this[_rid], chunk);
+ await op_ws_send_binary(this[_rid], chunk);
} else {
throw new TypeError(
"A chunk may only be either a string or an Uint8Array",
@@ -235,10 +245,7 @@ class WebSocketStream {
},
});
const pull = async (controller) => {
- const { 0: kind, 1: value } = await core.opAsync2(
- "op_ws_next_event",
- this[_rid],
- );
+ const { 0: kind, 1: value } = await op_ws_next_event(this[_rid]);
switch (kind) {
case 0:
@@ -402,7 +409,7 @@ class WebSocketStream {
this[_earlyClose] = true;
} else if (this[_closed].state === "pending") {
PromisePrototypeThen(
- core.opAsync("op_ws_close", this[_rid], code, closeInfo.reason),
+ op_ws_close(this[_rid], code, closeInfo.reason),
() => {
setTimeout(() => {
this[_closeSent].resolve(DateNow());