Skip to content

Commit 1e8183a

Browse files
authored
durable: add location hint support (#614)
1 parent 488e1b7 commit 1e8183a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

worker-sys/src/types/durable_object/namespace.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ extern "C" {
3434
this: &DurableObjectNamespace,
3535
id: &DurableObjectId,
3636
) -> Result<DurableObject, JsValue>;
37+
38+
#[wasm_bindgen(method, catch, js_name=get)]
39+
pub fn get_with_options(
40+
this: &DurableObjectNamespace,
41+
id: &DurableObjectId,
42+
options: &JsValue,
43+
) -> Result<DurableObject, JsValue>;
3744
}

worker/src/durable.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ impl ObjectId<'_> {
155155
})
156156
.map_err(Error::from)
157157
}
158+
159+
pub fn get_stub_with_location_hint(&self, location_hint: &str) -> Result<Stub> {
160+
let options = Object::new();
161+
js_sys::Reflect::set(
162+
&options,
163+
&JsValue::from("locationHint"),
164+
&location_hint.into(),
165+
)?;
166+
167+
self.namespace
168+
.ok_or_else(|| JsValue::from("Cannot get stub from within a Durable Object"))
169+
.and_then(|n| {
170+
Ok(Stub {
171+
inner: n.inner.get_with_options(&self.inner, &options)?,
172+
})
173+
})
174+
.map_err(Error::from)
175+
}
158176
}
159177

160178
impl Display for ObjectId<'_> {

0 commit comments

Comments
 (0)