notifyOne method
void
notifyOne()
Wake up exactly one waiter, or store one permit if no waiters.
If there are waiting tasks, wakes the first one. If no tasks are waiting, stores a permit that will be consumed by the next notified call.
Use cases:
- Single resource became available
- One-time configuration change
- Single task completion notification
Example:
// Resource pool - notify when one resource is free
void releaseResource() {
returnResourceToPool();
resourceAvailable.notifyOne(); // Wake one waiting task
}
Implementation
void notifyOne() {
if (_closed) return;
_epoch++;
for (var i = 0; i < _waiters.length; i++) {
final c = _waiters.removeAt(0);
if (!c.isCompleted) {
c.complete();
return;
}
}
_permits++;
}