0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

perf(ext/websocket): special op for sending text data frames (#18507)

Similar to #18506 but for Text frames.
This commit is contained in:
Divy Srivastava 2023-03-30 21:22:12 +05:30 committed by GitHub
parent 3abc53f811
commit cc7f5c1015
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -325,10 +325,7 @@ class WebSocket extends EventTarget {
const d = core.encode(string);
this[_bufferedAmount] += d.byteLength;
PromisePrototypeThen(
core.opAsync("op_ws_send", this[_rid], {
kind: "text",
value: string,
}),
core.opAsync("op_ws_send_text", this[_rid], string),
() => {
this[_bufferedAmount] -= d.byteLength;
},

View file

@ -402,6 +402,20 @@ pub enum SendValue {
Ping,
}
#[op]
pub async fn op_ws_send_text(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
data: String,
) -> Result<(), AnyError> {
let resource = state
.borrow_mut()
.resource_table
.get::<WsStreamResource>(rid)?;
resource.send(Message::Text(data)).await?;
Ok(())
}
#[op]
pub async fn op_ws_send(
state: Rc<RefCell<OpState>>,
@ -504,6 +518,7 @@ deno_core::extension!(deno_websocket,
op_ws_send,
op_ws_close,
op_ws_next_event,
op_ws_send_text,
],
esm = [ "01_websocket.js", "02_websocketstream.js" ],
options = {