Module locks
The Web Locks API (src/page/bindings_locks.odin): navigator.locks.request / query, held per origin and shared across every page and worker of that origin in this process. The grant order, the shared/exclusive rule, ifAvailable, steal and the waiting queue are native; the engine holds each request's callback and the promise it returns and runs the callback when the host grants the lock (wj_cb_lock_granted).
Exposed to: Window, Worker. Source: api/locks.widl.
Odin: import "wren:locks".
Types
enum LockMode : i32
A lock mode (LockMode).
| member | value | |
|---|---|---|
Shared | 0 | |
Exclusive | 1 |
Functions
LockManager_request
i64 LockManager_request(string name, LockMode mode, bool if_available, bool steal, u32 callback, i32 user, u32 broken_callback, bool has_signal)navigator.locks.request(name, {mode, ifAvailable, steal, signal}, callback). The result is packed: bit 0 is "available" (clear only for ifAvailable on a busy lock, or an opaque origin), bit 1 is "granted now" (run the callback with the Lock immediately), and the rest (>> 2) is the lock id used to release it. When available but not granted-now, the request waits and the engine is told on grant (the callback index / user name the engine record for that notification).
Host: LockManager_request :: proc(c: ^Call, name: string, mode: Api_LockMode, if_available: bool, steal: bool, callback: u32, user: i32, broken_callback: u32, has_signal: bool) -> i64
LockManager_release
void LockManager_release(u64 id)The callback's returned promise settled, the callback was null, or a pending request was aborted: release the lock (or drop the queued request) and grant whatever waits.
Host: LockManager_release :: proc(c: ^Call, id: u64)
LockManager_queryCount
i32 LockManager_queryCount(bool held)navigator.locks.query(): the number of held / pending locks of the caller's origin, and the i-th entry's fields.
Host: LockManager_queryCount :: proc(c: ^Call, held: bool) -> i32
LockManager_queryName
string LockManager_queryName(bool held, i32 index) raisesRaises: returns an Error (see web).
Host: LockManager_queryName :: proc(c: ^Call, held: bool, index: i32) -> (string, Api_Error)
LockManager_queryMode
string LockManager_queryMode(bool held, i32 index) raisesRaises: returns an Error (see web).
Host: LockManager_queryMode :: proc(c: ^Call, held: bool, index: i32) -> (string, Api_Error)
LockManager_queryClient
string LockManager_queryClient(bool held, i32 index) raisesRaises: returns an Error (see web).
Host: LockManager_queryClient :: proc(c: ^Call, held: bool, index: i32) -> (string, Api_Error)