Import std.concurrent.tasks
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.
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
-
A new TaskSource, whose Task isn't done.
-
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.
-
Whether Finish has given the result.
-
Gives the Task its result, which wakes what waits for it. Panics when it has one already.
-
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.