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:
parent
3abc53f811
commit
cc7f5c1015
2 changed files with 16 additions and 4 deletions
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue