- monitor(watched, observer, msg): registration lives on the watched actor's home thread (kind-7 envelope cross-shard); actor_die walks the list; already-dead fires NOW; the notice msg moves; a full observer's notice drops with a stderr line (no fiber to trap) - time.after(ms, addr, msg): per-shard timer list riding the deadline machinery (uring tick min + epoll timeout both include timers; fired from the same sweep); ms <= 0 delivers now; NO cancel — the generation-counter idiom is pinned by run/timer-generation - runtime_notify: one runtime-sourced delivery path (notices, timers) — reserve-or-drop, cross-shard via kind-0 envelopes - compiler: monitor typed as a bespoke free fn (notice typed against the OBSERVER's mailbox — the three-argument deviation, disclosed); time.after as a stdlib row whose msg arg is EXEMPT from the module- call fresh-arg drop (it moves — the double-own bug the timer fixture caught); owner move slots for both - corpus: run/monitor-death (trap-death + already-dead notices), run/timer-delivery (armed + immediate), run/timer-generation - teardown drops undelivered notices and unfired timers; battery 13/13 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
28 lines
631 B
Text
28 lines
631 B
Text
use time
|
|
|
|
-- iteration 24 T5: the CANCEL idiom — no cancel builtin, a generation
|
|
-- counter instead. The actor bumps its generation; a stale timer's
|
|
-- message names the old one and is recognized and ignored on arrival.
|
|
class Timer {
|
|
gen: Int
|
|
}
|
|
|
|
class Gate {
|
|
gen: Int
|
|
fn receive(msg: Timer) {
|
|
if msg.gen == self.gen {
|
|
print("fired gen ${msg.gen}");
|
|
} else {
|
|
print("stale gen ${msg.gen} ignored");
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() -> Int {
|
|
let g: actor Timer = spawn Gate { gen: 2 };
|
|
time.after(30, g, Timer { gen: 1 });
|
|
time.after(60, g, Timer { gen: 2 });
|
|
time.sleep(200);
|
|
print("done");
|
|
return 0;
|
|
}
|