Expand description
§cross‑locks
A single‑source, zero‑dependency¹ implementation of Supabase/GoTrue‑style global exclusive locks that work identically across every runtime.
| target / runtime | compile‑time feature | backend used by DefaultLock |
|---|---|---|
| Native (Tokio, multi‑thread) | native | fair FIFO queue (Notify) |
Browser WASM (2022 + navigator.locks) | browser | Navigator.locks.request |
| Head‑less WASM (Node / WASI / tests) | wasm | no‑op passthrough |
* Safari shipped the LockManager API in 16.4 (2023‑03).
§Guarantees
- FIFO fairness for every waiter requesting the same lock name on native.
- Zero‑timeout try‑lock (
Duration::ZERO) mirrors the semantics of the JS SDK. - Task‑local re‑entrancy helper demonstrated in the test‑suite.
Arc<T>automatically implementsGlobalLock, ideal for storing in anAxumState,OnceCell, etc.
¹ Outside the optional features listed below (async‑trait, thiserror,
Tokio / wasm‑bindgen).
# Cargo.toml – choose exactly ONE backend
[dependencies]
cross-locks = { version = "*", default-features = false, features = ["native"] }
# or "browser" | "wasm"# run the exhaustive native test‑suite
cargo test --features native
# browser smoke‑test (headless Firefox)
wasm-pack test --firefox --headless --features browserMacros§
- async_
test - Expands to
tokio::teston native targets and to awasm_bindgen_testmodule onwasm32(so the name doesn’t clash with the outer function space). - dual_
test - Shorthand when you don’t need a dedicated module on wasm
(i.e. the test name is unique anyway).
Generates either a
tokio::testor awasm_bindgen_testfor the same async function.
Structs§
- Noop
Lock - Passthrough implementation – used by the
wasm(Node/WASI) feature and in single‑thread CLI tests.
Enums§
- Lock
Error - Errors returned by
GlobalLock::with_lock.
Traits§
- Global
Lock - Back‑end agnostic trait.
On
wasm32theSendbounds are automatically relaxed (?Send).