Skip to content

Conversation

guybedford
Copy link
Collaborator

This provides a possible implementation for a SharedDurableObject trait which does not implement the &mut self pattern but instead implements &self to allow multiple concurrent borrowers.

This then pushes the concurrency problem for durable object access down into field cells, where any standard Rust techniques can then be used to manage mutable field access - Mutex / RwLock / RefCell etc.

The test here uses the RefCell approach for mutable fields, where so long as mutable borrows are not held over async points there will never be a panic.

While formally we are single threaded, blanket turning off concurrency checks on mutable access may have implications for undefined Rust compiler behaviours. So instead this approach aligns with Rust conventions, even though threaded code is not in play.

I think these idioms should be perfectly comfortable to Rust devs (far more than relaxing mutable behaviours), even if they don't fully apply in this single threaded JS embedding environment it remains closer to the proper way of doing things without much ergonomic cost.

@guybedford guybedford force-pushed the gbedford/shared-durable-object branch from b92ffdc to 153f1f0 Compare May 30, 2025 00:08
@edevil
Copy link
Contributor

edevil commented May 30, 2025

Not all heroes wear capes.

@guybedford
Copy link
Collaborator Author

Superseded by #753.

@guybedford guybedford closed this Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants