Skip to content
FutureBlitz

    Install

    Import std.concurrent.tasks

    ThrowingTaskSource

    std.concurrent.tasks

    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.

    Examples

    Local source = ThrowingTaskSource<Int, ParseError>()
    Local task = source.Task
    source.Fail(ParseError(ParseErrorKind.SYNTAX, "not a number"))
    Expect(ExpectThrows<ParseError>(task.Wait()) != Null)

    std/concurrent/tasks.fb, line 107

    • 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.

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