lightspeed/async/backpressure
Async runtime boundaries for cancellation and backpressure-aware adapters.
Types
Adapter mode used for async runtime scheduling.
pub type AdapterMode {
PushPull
PushOnly
PullOnly
}
Constructors
-
PushPull -
PushOnly -
PullOnly
Runtime boundary contract for async scheduling.
pub type Boundary {
Boundary(
mode: AdapterMode,
max_in_flight: Int,
max_queued: Int,
cancellation_budget_ms: Int,
)
}
Constructors
-
Boundary( mode: AdapterMode, max_in_flight: Int, max_queued: Int, cancellation_budget_ms: Int, )
Runtime
opaqueAsync runtime state with explicit backpressure limits.
pub opaque type Runtime
Task transition errors.
pub type RuntimeError {
DuplicateTask(key: String)
QueueSaturated(key: String, max_queued: Int)
UnknownTask(key: String)
InvalidTransition(key: String, state: String, action: String)
}
Constructors
-
DuplicateTask(key: String) -
QueueSaturated(key: String, max_queued: Int) -
UnknownTask(key: String) -
InvalidTransition(key: String, state: String, action: String)
Lifecycle state of one async task.
pub type TaskState {
Queued(seq: Int)
InFlight(seq: Int, started_ms: Int)
Succeeded(seq: Int)
Failed(seq: Int, reason: String)
Cancelled(seq: Int, reason: String)
}
Constructors
-
Queued(seq: Int) -
InFlight(seq: Int, started_ms: Int) -
Succeeded(seq: Int) -
Failed(seq: Int, reason: String) -
Cancelled(seq: Int, reason: String)
Values
pub fn boundary(
mode: AdapterMode,
max_in_flight: Int,
max_queued: Int,
cancellation_budget_ms: Int,
) -> Boundary
Build a boundary profile.
pub fn cancel(
runtime: Runtime,
key: String,
reason: String,
) -> #(Runtime, Result(Nil, RuntimeError))
Cancel one queued or in-flight task.
pub fn default_boundary() -> Boundary
Default boundary profile for mixed push/pull adapters.
pub fn enqueue(
runtime: Runtime,
key: String,
) -> #(Runtime, Result(Nil, RuntimeError))
Enqueue one task with backpressure checks.
pub fn fail(
runtime: Runtime,
key: String,
reason: String,
) -> #(Runtime, Result(Nil, RuntimeError))
Mark one in-flight task as failed.
pub fn retry(
runtime: Runtime,
key: String,
) -> #(Runtime, Result(Nil, RuntimeError))
Retry a failed/cancelled task by putting it back in queue.
pub fn signature(runtime: Runtime) -> String
Stable runtime signature for deterministic fixtures.
pub fn start_available(
runtime: Runtime,
now_ms: Int,
) -> #(Runtime, List(String))
Start queued tasks up to in-flight limit.
pub fn state(
runtime: Runtime,
key: String,
) -> option.Option(TaskState)
Lookup task state by key.
pub fn succeed(
runtime: Runtime,
key: String,
) -> #(Runtime, Result(Nil, RuntimeError))
Mark one in-flight task as succeeded.