AsyncSignal class
AsyncSignal
Control the flow of asynchronous operations by signaling all the waiting tasks whether they should wait or continue at a specific point.
Lock or unlock the flow.
Usage
final signal = AsyncSignal(locked: true);
void getIn() async {
await signal.wait();
print('Finally, I\'m in!');
}
getIn();
print('Wait, I will open the door after 3 seconds.');
await Future.delayed(const Duration(seconds: 3));
print('Opening the door...');
signal.unlock();
// [Output]
// Wait, I will open the door after 3 seconds.
// 3 seconds later...
// [Output]
// Opening the door...
// Finally, I'm in!
Constructors
- AsyncSignal({bool locked = false})
Properties
-
future
→ Future<
bool> -
Future with the next signal state.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- locked ↔ bool
-
Set the signal state. This works the same as lock and unlock methods.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
→ Stream<
bool> -
Stream of the signal state.
no setter
Methods
-
close(
) → void - Closing the signal will make it not signal any future waiting tasks.
-
lock(
) → void - Locking will prevent everyone waiting from passing through, until unlocked.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unlock(
) → void - Unlocking will allow everyone who was waiting to pass through.
-
wait(
) → Future< void> - Wait until the signal is unlocked.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited