Systems
·
v0.0.13
Async / await
import "stdlib/future" as future;
import "stdlib/executor" as executor;
async fn inner() -> i32 { return 7; }
async fn outer() -> i32 {
let x: i32 = await inner();
return x +% 1;
}
fn main() -> i32 {
let f: future::Future[i32] = outer();
return executor::block_on::[i32](f);
}
Signature rules
- An
async fnreturnsFuture[T], written as the bareTin the signature. await EXPRsuspends untilEXPR(a future) resolves and yields its value.- Borrow-shaped parameters (
str,T[],mut x: NonCopyT) are rejected in anasync fnsignature (E0900), because a suspension can outlive the caller's frame. PassstringandVec[T]instead.
Reactor: concurrent I/O
The reactor (kqueue on macOS) makes async actually concurrent rather than just structured. It provides cooperative primitives over stdlib/executor, stdlib/reactor, and stdlib/time, so awaiting a timer or socket yields the executor to other ready tasks instead of blocking the thread.