GlobalLock class abstract

A lock shared beyond the current isolate, identified by its name.

Two GlobalLock objects with the same name exclude each other:

  • io (Dart VM, Flutter mobile and desktop): across all the isolates and processes of the machine run by the same user. The lock is a file created exclusively in /tmp/synchronized_global_lock_<user> (Linux, macOS) or the system temp folder (elsewhere), touched every second by a heartbeat isolate, so the lock stays held while the event loop of the holder is blocked (synchronous work). The lock is released at once when the holder isolate exits without releasing it; a waiter takes over a file not touched for 10 seconds, so a holder process that died (crash, kill) blocks the others for 10 seconds at most.
  • web: across the tabs and workers of the same origin, using the Web Locks API (navigator.locks); the browser releases it when the tab closes.
  • node (its Web Locks API, node 24+): within the current process only (and its worker threads), not across processes.
  • elsewhere (no Web Locks API): within the current isolate only.

Not reentrant: acquiring it again while holding it waits for itself (until the timeout, if any).

Implementers

Constructors

GlobalLock(String name)
Creates a lock named name.
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String
The lock name, the same for all the users of the lock.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

acquire({Duration? timeout}) → Future<GlobalLockHandle>
Waits for the lock and holds it until GlobalLockHandle.release.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
synchronized<T>(FutureOr<T> computation(), {Duration? timeout}) → Future<T>
Runs computation holding the lock, released when it completes.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited