RoundRobin
Defined in: packages/async/src/synchro/round-robin.ts:26
Hands one turn at a time to a fixed set of participants, cyclically.
Every participant takes a turn before any one of them takes a second, and turns never overlap — the next holder is only woken once the previous one has released it. A participant that finishes early leaves, and the remaining ones carry on without it, still strictly one at a time.
Example
Section titled “Example”const turns = new RoundRobin(3);
async function worker(id: number, batches: number) { await turns.take(id); try { for (let batch = 0; batch < batches; batch++) { // ...do this worker's share of one round... if (batch < batches - 1) { await turns.next(id); } } } finally { turns.leave(id); } }Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RoundRobin(
participants):RoundRobin
Defined in: packages/async/src/synchro/round-robin.ts:38
Parameters
Section titled “Parameters”participants
Section titled “participants”number
How many fixed, 0-based participant slots to cycle through.
Returns
Section titled “Returns”RoundRobin
Accessors
Section titled “Accessors”maxRounds
Section titled “maxRounds”Get Signature
Section titled “Get Signature”get maxRounds():
number
Defined in: packages/async/src/synchro/round-robin.ts:95
Turns taken by the participant that took the most.
Returns
Section titled “Returns”number
minRounds
Section titled “minRounds”Get Signature
Section titled “Get Signature”get minRounds():
number
Defined in: packages/async/src/synchro/round-robin.ts:107
Turns taken by the participant that took the fewest.
The rounds up to this point are the only ones every participant took part in: past it, at least one participant had already left, so whatever ran the turn alongside it did so under different conditions (less contention, different concurrent load).
Returns
Section titled “Returns”number
Methods
Section titled “Methods”leave()
Section titled “leave()”leave(
id):void
Defined in: packages/async/src/synchro/round-robin.ts:84
Gives up this participant’s turn for good.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
next()
Section titled “next()”next(
id):Promise<void>
Defined in: packages/async/src/synchro/round-robin.ts:63
Passes the turn on, and waits for it to come back.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”Promise<void>
take()
Section titled “take()”take(
id):Promise<void>
Defined in: packages/async/src/synchro/round-robin.ts:52
Resolves when it is this participant’s turn.
Parameters
Section titled “Parameters”number
0-based participant index, in turn order.
Returns
Section titled “Returns”Promise<void>