SynchronizedLock class

A reentrant async lock for critical section execution.

This class serializes access to an async FutureOr function by maintaining a queue. Reentrancy is supported within the same Zone.

Features:

  • Queue-based task execution for synchronizedAsync
  • Reentrancy (based on Dart zones) for both synchronized and synchronizedAsync

Example:

final lock = SynchronizedLock();

await lock.synchronizedAsync(() async {
  // Only one async block can execute here at a time
});

lock.synchronized(() {
  // Only one sync block can execute here at a time,
  // and it will not queue if another zone holds the lock.
});

Constructors

SynchronizedLock()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
synchronized<T>(T action()) → T
Executes the action within a synchronous synchronized block.
synchronizedAsync<T>(FutureOr<T> action()) Future<T>
Executes the action within an asynchronous synchronized block.
toString() String
A string representation of this object.
inherited

Operators

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