Search results

There are no results.

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)

class async Example {
  fn async write(promise: uni Promise[Int]) {
    promise.set(42)
  }
}

class async Main {
  fn async main {
    match Future.new {
      case (future, promise) -> {
        Example().write(promise)
        future.get # => 42
      }
    }
  }
}

Classes

Channel

An unbounded multiple publisher multiple consumer channel, implemented using a process and the Future and Promise types.

Future

A proxy value to resolve into the result of some asynchronous operation.

Promise

The writing half of a future.