Examples · learn/21-concurrency · 255 of 339
within
tin run examples/learn/21-concurrency/within.tinfn crunch(label: string, cost: Duration): string {
sleep(cost)
"{label} done"
}
fn main() {
print(spawn crunch("quick", 5ms) |> within(1s)) // Some(...): finished in time
print(spawn crunch("endless", 1h) |> within(20ms)) // None: stopped after 20ms
}