Task α
is a primitive for asynchronous computation.
It represents a computation that will resolve to a value of type α
,
possibly being computed on another thread. This is similar to Future
in Scala,
Promise
in Javascript, and JoinHandle
in Rust.
The tasks have an overridden representation in the runtime.
Constructor
Task.pure.{u}
Task.pure (a : α)
constructs a task that is already resolved with value a
.
Fields
get : α
Blocks the current thread until the given task has finished execution, and then returns the result of the task. If the current thread is itself executing a (non-dedicated) task, the maximum threadpool size is temporarily increased by one while waiting so as to ensure the process cannot be deadlocked by threadpool starvation. Note that when the current thread is unblocked, more tasks than the configured threadpool size may temporarily be running at the same time until sufficiently many tasks have finished.
Task.map
and Task.bind
should be preferred over Task.get
for setting up task dependencies
where possible as they do not require temporarily growing the threadpool in this way.