Chain a future

future.then(callback) transforms success; catch(callback) recovers an asynchronous failure. A callback may return a value or another future, which is flattened one level.

Expected domain failure still belongs in Result. Continuations keep async diagnostics until a final await decides whether the failure was recovered.

async fn number() -> int { 6 }

async fn main() {
  let doubled = number().then(|value| value * 2)
  println(await doubled)
}
Output & diagnostics
Expected:
12
Ctrl/⌘+Enter runs the current lesson.