Guide
async & tasks
Since Sprint 67, async means something — the smallest true semantics: calling an async fn runs nothing and yields a Task[T]; .run() is the only way anything happens. Deterministic, no scheduler, no await.
import tasks
async fn fetch_score(player: Text) -> Int:
print("scoring {player}...")
return player.len() * 10
fn main() -> Void:
let t = fetch_score("ada")
print("nothing has run yet")
print("ada: {t.run()}")
let scores = tasks.all([
fetch_score("grace"),
fetch_score("alan"),
])
print("all: {scores}")$ ptc run scores.pt
Recorded output of the real compiler
The first line proves the deferral: creating the Task printed nothing. tasks.all — stdlib, written in POLYTONE — drives a list in order and collects the results. And the misuses teach, like everything else here:
async fn ping() -> Int = 1
fn main() -> Void:
ping()$ ptc check dropped.pt
Recorded output of the real compiler