Crate weblocks

Crate weblocks 

Source
Expand description

RAII-style Rust wrapper around the Web Locks API (navigator.locks).

Notes

  • This uses web-sys unstable bindings and requires compiling with --cfg web_sys_unstable_apis.
  • Target must be wasm32-unknown-unknown and run in a browser environment.

Example

// Build with: RUSTFLAGS="--cfg=web_sys_unstable_apis"
use weblocks::{acquire, AcquireOptions, LockMode};

let _guard = acquire("my_resource", AcquireOptions::exclusive())
    .await?;
// Lock held while `_guard` is in scope; released on drop.

Structs§

AcquireOptions
Options to control how a lock request is made.
LockGuard
Guard that holds a Web Lock until dropped.

Enums§

LockMode
Lock mode for the Web Locks API.

Functions§

acquire
Non-wasm target stub that returns an error at runtime.
is_supported
Returns true if navigator.locks is available in this environment.