Permit

interface Permit(source)

A granted unit of budget. Charged at the grant, so a permit never completed is simply spent: the budget holds no lock or lease for it. Not AutoCloseable: its completion is suspend.

Experimental (implement). Implementing needs @OptIn(ExperimentalForInheritanceWebToolsApi::class); calling complete and release is Stable Core. complete means the request was sent; release means it never was and refunds the units. Both are idempotent, run under NonCancellable (so they take effect from a cancelled coroutine), and a complete after a release, or the reverse, is ignored.

Properties

Link copied to clipboard
abstract val cost: Int

The units this permit charged.

Link copied to clipboard
abstract val lane: Lane

The lane it was granted on.

Functions

Link copied to clipboard
open suspend fun complete()

complete with RateSignals.None: the request was sent and nothing is known about the answer.

abstract suspend fun complete(signals: RateSignals)

The request was sent and signals were read from its answer: reconcile counts and pause on a throttle.

Link copied to clipboard
abstract suspend fun release()

The request was never sent: refund the units and re-plan the waiters.