acquire

open suspend override fun acquire(cost: Int, lane: Lane, maxWait: Duration): Result<Permit>(source)

Charges cost units to lane now, or once a slot within maxWait comes (contract points 1 to 5).

Return

a permit; Result.failure of HttpFailure.BudgetExhausted when the call would wait longer than maxWait (or can never fit); Result.failure of HttpFailure.Closed (component "budget") after close.

Parameters

cost

the units to charge; at least 1.

lane

the lane to charge.

maxWait

the longest the call may wait for its slot; Duration.INFINITE waits as long as the plan needs.

Throws

if cost is below 1 or maxWait is negative.

kotlinx.coroutines.CancellationException

if the caller is cancelled.