std/task
On this page
Index
- type
Timed - type
Isolated - type
Fault - type
Budgeted - type
Budget - type
Group- method
Group.spawn - method
Group.spawn_background
- method
- type
Semaphore- method
Semaphore.with
- method
- type
Once- method
Once.get
- method
- fn
budget - fn
with_budget - fn
with_timeout - fn
isolate - fn
is_canceled - fn
stop_requested - fn
stopping - fn
deadline - fn
map_concurrent - fn
map_concurrent_until - fn
semaphore - fn
once
Types
Timed
enum Timed[E] {
TimedOut
Failed(from E)
} derive DisplayIsolated
enum Isolated[E] {
Faulted(info: Fault)
Failed(from E)
} derive DisplayFault
struct Fault {
msg: Str
location: Str
frames: List[Str]
} derive DisplayBudgeted
enum Budgeted[E] {
Exceeded(resource: Str)
Failed(from E)
} derive DisplayThe outcome of task.with_budget (decision 0173): a ceiling was passed (resource is “cpu”, “alloc”, or “steps”), or f failed.
Budget
struct Budget {
cpu: Duration
alloc: Int
steps: Int
}Ceilings on the work of a call run by task.with_budget (decision 0173): running time, bytes allocated, and steps (loop iterations and calls). Zero means no ceiling.
Group
struct Group {}A task group (core 7.1): created by s.group() or given as os.tasks.
Its tasks belong to the scope that created it.
Group.spawn
fn (g: Group) spawn[T, E, fx: Effects](f: fn() -> T ! E uses fx) -> Task[T, E] uses fxGroup.spawn_background
fn (g: Group) spawn_background[E, fx: Effects](f: fn() -> () ! E uses fx) uses fxSemaphore
struct Semaphore {}Semaphore.with
fn (s: Semaphore) with[R, E, fx: Effects](f: fn() -> R ! E uses fx) -> R ! E uses fxOnce
struct Once[T, E] {}Single flight with a shared result (decision 0043): the first caller of
get runs f; concurrent and later callers wait for and share its result.
If the running caller is cancelled before f finishes, the next waiter
runs f instead. A failed result is shared too.
Once.get
fn (o: Once[T, E]) get[fx: Effects](f: fn() -> T ! E uses fx) -> T ! E uses fxFunctions
budget
fn budget(cpu: Duration = 0s, alloc: Int = 0, steps: Int = 0) -> Budgetwith_budget
fn with_budget[T, E, fx: Effects](clock: Clock, b: Budget, f: fn() -> T ! E uses fx) -> T ! Budgeted[E] uses (clock, fx)Runs f in a child scope under the budget b: when a ceiling is passed the scope is canceled, its tasks unwind at their next loop iteration or call, and the result is Err(Exceeded(resource)).
with_timeout
fn with_timeout[T, E, fx: Effects](clock: Clock, d: Duration, f: fn() -> T ! E uses fx) -> T ! Timed[E] uses (clock, fx)isolate
fn isolate[T, E, fx: Effects](f: fn() -> T ! E uses fx) -> T ! Isolated[E] uses fxis_canceled
fn is_canceled() -> Boolstop_requested
fn stop_requested() -> BoolThe first shutdown signal arrived (core 7.5).
stopping
fn stopping() -> Chan[()]A channel closed when a stop is requested (core 7.5).
deadline
fn deadline(clock: Clock) -> Time? uses clockThe nearest with_timeout deadline the current task works under, as an instant on clock, or None (decision 0430). A task keeps the deadline in force where it was spawned.
map_concurrent
fn map_concurrent[T, R, E, fx: Effects](items: List[T], limit: Int, f: fn(T) -> R ! E uses fx) -> List[Result[R, E]] uses fxmap_concurrent_until
fn map_concurrent_until[T, R, E, fx: Effects](clock: Clock, d: Duration, items: List[T], limit: Int, f: fn(T) -> R ! E uses fx) -> List[Result[R, Timed[E]]] uses (clock, fx)Like map_concurrent, but items not finished after d are cancelled and give Err(TimedOut); finished results are kept, in input order.
semaphore
fn semaphore(permits: Int) -> Semaphoreonce
fn once[T, E]() -> Once[T, E]