async_signal

Last updated:

0 purchases

async_signal Image
async_signal Images
Add to Cart

Description:

async signal

Async Signal #
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.
Features #

Control the flow of asynchronous operations
Check the status of the signal
Wait for the signal to be unlocked

Getting started #
Install it using pub:
flutter pub add async_signal
copied to clipboard
And import the package:
import 'package:async_signal/async_signal.dart';
copied to clipboard
Usage #
final signal = AsyncSignal();

// Start with it locked
final signal = AsyncSignal(locked: true);
copied to clipboard
Lock or unlock to let everything waiting go through
signal.lock();
signal.unlock();
copied to clipboard
Wait for the signal to be unlocked, if it's already unlocked you will go right through it
await signal.wait();
copied to clipboard
Close the signal when you're done using it
signal.close();
copied to clipboard
Is this what you're looking for? #
async_signal allows you to control a flow, allowing multiple operations to continue at once only when you want, like opening a gate.
If what you're looking for is one by one like a queue, then check out the async_locks package.
GitHub #
The package code is available on Github: Dart - AsyncSignal
Example #
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!
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.