TurboMutex class
A utility class that provides mutual exclusion functionality.
TurboMutex helps manage concurrent access to resources by ensuring that only one operation can execute at a time. Operations are queued and executed in order.
Example:
final mutex = TurboMutex();
// Run operations with mutual exclusion
await mutex.lockAndRun(
run: (unlock) async {
// Do something that needs exclusive access
await someOperation();
unlock(); // Release the lock
},
);
// Clean up
mutex.dispose();
Constructors
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
-
dispose(
) → void - Disposes of the mutex by clearing all pending operations.
-
lockAndRun<
T> ({required FutureOr< T> run(VoidCallback unlock)}) → FutureOr<T> - Locks the mutex, runs the provided function, and releases the lock.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited