IConcurrencySystem
Implemented by
Index
Properties
readonlycurrentConcurrency
The number of parallel tasks currently booked against this governor, regardless of which pool booked them.
readonlydesiredConcurrency
The number of tasks that should currently be running in parallel, assuming a sufficient supply of them. How it
is derived is up to the implementation, hence read-only here — but it must always be at least 1, or a pool
could never start the first task.
readonlyisRunning
Whether the governor is ready to be booked against. pool.run() refuses to run
when this is false. An implementation with no startup lifecycle simply reports true.
Methods
hasCapacityForTask
May one more task start right now, on behalf of
consumer? A cheap pre-check the pool consults before querying task readiness.Must not enforce rate limits that only make sense for ready tasks (e.g. a per-minute task cap): the pool calls this before knowing whether any task is ready, so refusing here would stall an already-empty queue.
Must also return
truewheneverconsumerhas nothing in flight of its own. Afalsesends that pool straight to its finished-check without consultingisTaskReadyFunction, so a governor that starves an idle pool can make itsrun()resolve while work is still pending. Tracking bookings per consumer answers that directly; ConcurrencySystem, which does not, instead never refuses whilecurrentConcurrencyis0.Parameters
consumer: ConcurrencyConsumer
Returns boolean
registerTaskEnd
Returns a task's slot to
consumer's budget. Called once the task settles (resolve or reject).Parameters
consumer: ConcurrencyConsumer
Returns void
tryRegisterTaskStart
Books a task against the budget for
consumer, returningfalse(without booking) when there is no room — the budget is spent, the consumer is over its share, or an implementation-specific rate limit was reached.Must be an atomic (synchronous) check-and-book: several pools may share one governor, and a check separated from the booking by an
awaitlets two of them claim the last free slot at once.Parameters
consumer: ConcurrencyConsumer
Returns boolean
The contract between an AutoscaledPool and its concurrency "governor" — the object that answers is there free compute for one more task? and tracks the budget that tasks are booked against. ConcurrencySystem is the canonical implementation; the interface lets alternate governors be substituted without depending on its internals.
Every allocation method is told which consumer is asking, so an implementation can allocate per consumer. ConcurrencySystem does not: it serves whoever asks first, which can starve a pool that joins a saturated system late.