Skip to content

Implement Send, Sync and Clone for some Durable Object types #563

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

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions worker-sys/src/types/durable_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use transaction::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends=js_sys::Object)]
#[derive(Clone)]
pub type DurableObject;

#[wasm_bindgen(method, catch, js_name=fetch)]
Expand Down
1 change: 1 addition & 0 deletions worker-sys/src/types/durable_object/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::types::{DurableObject, DurableObjectId};
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends=js_sys::Object)]
#[derive(Clone)]
pub type DurableObjectNamespace;

#[wasm_bindgen(method, catch, js_name=idFromName)]
Expand Down
7 changes: 7 additions & 0 deletions worker/src/durable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub struct Stub {
inner: EdgeDurableObject,
}

unsafe impl Send for Stub {}
unsafe impl Sync for Stub {}

impl Stub {
/// Send an internal Request to the Durable Object to which the stub points.
pub async fn fetch_with_request(&self, req: Request) -> Result<Response> {
Expand All @@ -59,10 +62,14 @@ impl Stub {
/// Use an ObjectNamespace to get access to Stubs for communication with a Durable Object instance.
/// A given namespace can support essentially unlimited Durable Objects, with each Object having
/// access to a transactional, key-value storage API.
#[derive(Clone)]
pub struct ObjectNamespace {
inner: EdgeObjectNamespace,
}

unsafe impl Send for ObjectNamespace {}
unsafe impl Sync for ObjectNamespace {}

impl ObjectNamespace {
/// This method derives a unique object ID from the given name string. It will always return the
/// same ID when given the same name as input.
Expand Down
Loading