Move throttling
diff --git a/lib/src/back_end/worker_pool.dart b/lib/src/back_end/worker_pool.dart index 63415e6..4e250af 100644 --- a/lib/src/back_end/worker_pool.dart +++ b/lib/src/back_end/worker_pool.dart
@@ -79,11 +79,6 @@ }) async { if (_isClosed) throw StateError('WorkerPool is closed'); - if (_inMemoryCount >= maxBacklog) { - _throttleCompleter ??= Completer<void>(); - await _throttleCompleter!.future; - } - _inMemoryCount++; var request = _WorkerRequest( @@ -110,6 +105,11 @@ if (_pending.length >= _batchSize) { _flush(); } + + if (_inMemoryCount >= maxBacklog) { + _throttleCompleter ??= Completer<void>(); + return _throttleCompleter!.future; + } } /// Sends a batch of requests to a worker.