onIdle property

Future<void> get onIdle

Returns a Future that completes when the queue is empty and active count is 0.

Uses event-based notification for efficiency (no polling).

If the limiter is already idle, returns a completed Future immediately.

Example:

final limit = fLimit(2);

// Add tasks...
for (int i = 0; i < 10; i++) {
  limit(() async => processItem(i));
}

// Wait for all to finish
await limit.onIdle;
print('All tasks completed!');

Implementation

Future<void> get onIdle {
  if (isEmpty) {
    return Future.value();
  }

  final completer = Completer<void>();
  _idleCompleters.add(completer);
  return completer.future;
}