-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Hibernatable Web Sockets API #436
Changes from 14 commits
843a3e4
b65cefe
7af7aa3
21fb6fd
b0b192f
949d25c
81029e6
1a1e70f
33f9c5a
fa15d2a
f06881c
11b89a7
ed8e8de
b64ffaf
f998701
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,21 @@ extern "C" { | |
|
||
#[wasm_bindgen(method, js_name=waitUntil)] | ||
pub fn wait_until(this: &DurableObjectState, promise: &js_sys::Promise); | ||
|
||
#[wasm_bindgen(method, js_name=acceptWebSocket)] | ||
pub fn accept_websocket(this: &DurableObjectState, ws: &web_sys::WebSocket); | ||
|
||
#[wasm_bindgen(method, js_name=acceptWebSocket)] | ||
pub fn accept_websocket_with_tags( | ||
this: &DurableObjectState, | ||
ws: &web_sys::WebSocket, | ||
tags: Vec<JsValue>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
|
||
#[wasm_bindgen(method, js_name=getWebSockets)] | ||
pub fn get_websockets(this: &DurableObjectState) -> Vec<web_sys::WebSocket>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why do there need to be two versions of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion (I am not the author), it's a style choice but this is probably the right one (in Rust anyway). It's slightly kinder to the caller to have two functions, and probably more idiomatic in Rust. Passing a parameter The rest of this crate seems to mostly follow this style as well, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's an unfortunate impedance mismatch between function overloading in JS and the lack thereof in Rust. I'm just trying to match the style of the rest of the repo which manually "un-overloads" the functions as Eric pointed out. I kind of wish Rust did have function overloading, but it probably has complicated interactions with the trait solver and type inference. |
||
|
||
#[wasm_bindgen(method, js_name=getWebSockets)] | ||
pub fn get_websockets_with_tag(this: &DurableObjectState, tag: &str) | ||
-> Vec<web_sys::WebSocket>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developers.cloudflare.com/durable-objects/platform/pricing/
The support of
acceptWebSocket()
is critical to many existing rust-based Durable Object applications since it would dramatically lower the cost incurred by WebSocket connection currently implemented byaccept()
method. Really appreciate your work!