Skip to content
FutureBlitz

    Install

    Import std.concurrent.tasks

    TaskSource

    std.concurrent.tasks

    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.

    Examples

    Local source = TaskSource<Int>()
    Local task = source.Task
    Expect(!source.IsDone)
    source.Finish(42)
    Expect(task.Wait() == 42 && source.IsDone)

    std/concurrent/tasks.fb, line 31

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

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