std.sync
Types for synchronizing operations.
Futures and promises
Two important types for synchronizing operations are Future and Promise. A
future is a proxy value to be resolved into a final value using a Promise. A
Future and its corresponding Promise are created using the Future.new
method. For example:
import std.sync (Future, Promise)
type async Example {
fn async write(promise: uni Promise[Int]) {
promise.set(42)
}
}
type async Main {
fn async main {
let (future, promise) = Future.new
Example().write(promise)
future.get # => 42
}
}
Types
| Channel | An unbounded multiple publisher multiple consumer channel, implemented using a
process and the | |
| Future | A proxy value to resolve into the result of some asynchronous operation. | |
| Promise | The writing half of a future. |