Skip to content
FutureBlitz

    Install

    Import std.concurrent.tasks

    std.concurrent.tasks

    Tasks made of other Tasks, and a Task finished by hand: WhenAll waits for each of its tasks, WhenAny for the first, and a TaskSource's Task is done once a thread has given it its result, and a ThrowingTaskSource's once the main thread has given it its result or its error. They give Tasks of Async Functions, so they're the main thread's, as Async code is.

    std/concurrent/tasks.fb

    Types

    TaskSource class

    Public Shared Class TaskSource<T: Sendable>

    A Task finished by hand: Finish, on any thread, gives its Task the result, which a Wait or an Await on the Task then gives. A TaskSource no thread finishes leaves its Task never done, like a Task that waits for a Scheduler that nothing ticks.

    std/concurrent/tasks.fb, line 19

    • Public New() constructor #

      A new TaskSource, whose Task isn't done.

    • Public Property Task: Task<T> property #

      A Task of the result: done at once when Finish has given it, and otherwise at the main thread's first tick after Finish does, as an Async Function's Task is once what it awaits is done. Each one it gives is a new Task of the same result. Only the main thread has one, as its code is Async code.

    • Public Property IsDone: Bool property #

      Whether Finish has given the result.

    • @PanicsAtCaller Public Method Finish(value: T) method #

      Gives the Task its result, which wakes what waits for it. Panics when it has one already.

    • Public Method TryFinish(value: T): Bool method #

      Gives the Task its result unless it has one already, and tells whether it didn't, so of threads that finish it at once, one does.

    ThrowingTaskSource class

    Public Class ThrowingTaskSource<T, E: Error>

    A Task finished by hand that can throw: Finish gives its Task the result, and Fail the error, which a Wait or an Await on the Task then gives or throws. An error isn't Sendable, so it's a Class, which stays on the main thread, as its Tasks do; work on other threads finishes a TaskSource instead. One that's never finished leaves its Task never done.

    std/concurrent/tasks.fb, line 86

    • Public New() constructor #

      A new ThrowingTaskSource, whose Task isn't done.

    • Public Property Task: (Task<T> Throws E) property #

      A Task of the result, or of the error: done at once when Finish or Fail has given it, and otherwise at the main thread's first tick after it does. Each one it gives is a new Task of the same result.

    • Public Property IsDone: Bool property #

      Whether Finish or Fail has given its Task what it gives.

    • @PanicsAtCaller Public Method Finish(value: T) method #

      Gives the Task its result, which wakes what waits for it. Panics when it has a result or an error already.

    • @PanicsAtCaller Public Method Fail(error: E) method #

      Gives the Task its error, which a Wait or an Await on it throws. Panics when it has a result or an error already.

    • Public Method TryFinish(value: T): Bool method #

      Gives the Task its result unless it has a result or an error already, and tells whether it didn't.

    • Public Method TryFail(error: E): Bool method #

      Gives the Task its error unless it has a result or an error already, and tells whether it didn't.

    Functions

    WhenAll function

    Public Function WhenAll<T>(tasks: Task<T>[]): Task<T[]>

    A Task of each task's result, in their order, done once they all are.

    std/concurrent/tasks.fb, line 156

    WhenAll function

    Public Function WhenAll(tasks: Task[]): Task

    A Task that's done once each of the tasks is.

    std/concurrent/tasks.fb, line 159

    WhenAll function

    Public Function WhenAll<T, E: Error>(tasks: (Task<T> Throws E)[]): (Task<T[]> Throws E)

    A Task of each task's result, in their order, done once they all are; when any throws, it waits for the rest and then throws the error of the first of them, in their order, that threw.

    std/concurrent/tasks.fb, line 178

    WhenAll function

    Public Function WhenAll<E: Error>(tasks: (Task Throws E)[]): (Task Throws E)

    A Task that's done once each of the tasks is, which throws the first's error, in their order, when any throw.

    std/concurrent/tasks.fb, line 184

    WhenAny function

    @PanicsAtCaller Public Function WhenAny<T>(tasks: Task<T>[]): Task<Int>

    A Task of the index of the first of the tasks found done, whose result a Wait or an Await then gives at once. At a tick of the scheduler it looks at them in their order, so of tasks done before it looks, it's the first in the array, and one done later in the tick doesn't count. Panics when there are none, since none would be done.

    std/concurrent/tasks.fb, line 221

    WhenAny function

    @PanicsAtCaller Public Function WhenAny(tasks: Task[]): Task<Int>

    A Task of the index of the first of the tasks to be done, as for tasks with results.

    std/concurrent/tasks.fb, line 233

    WhenAny function

    @PanicsAtCaller Public Function WhenAny<T, E: Error>(tasks: (Task<T> Throws E)[]): Task<Int>

    A Task of the index of the first of the tasks found done, as for tasks that don't throw: one that threw is done, and its Wait or Await then throws its error. Panics when there are none.

    std/concurrent/tasks.fb, line 246

    WhenAny function

    @PanicsAtCaller Public Function WhenAny<E: Error>(tasks: (Task Throws E)[]): Task<Int>

    A Task of the index of the first of the tasks to be done, or to throw. Panics when there are none.

    std/concurrent/tasks.fb, line 259

    Report an issue with this page or with FutureBlitz on GitHub.