Repository navigation
Commit 06d206d
committed
feat(timer): add the standard timer host module
Add the self-contained timer host-function module with
`timer::{at,every,pending_count,running_count}`, the `TimerBackend` contract,
`TimerConfig`/`TimerRegistration` admission limits, and the `TimerExtension`
composition/install entry point.
The module owns callback ownership transfer, the private callback VM, callback
state (Ready/Running/Waiting/Yielded/Complete/Cancelled), error isolation,
per-callback async bridges, and transactional registration rollback. The VM
core stays timer-free apart from the generic owned-value registry. Admission
limits travel with every registration and are MUST-enforce obligations on the
backend; `timer::pending_count` / `timer::running_count` are pure backend
queries and the module keeps no counters of its own.
The callback parameter is typed `fn(bool) -> unknown`: the callback observes
the `premature` flag and its return value is discarded, so the declared result
is `unknown` -- any `int`/`string`/`map`/`bool`/`null` body compiles and runs,
and the value is dropped instead of accumulating. This is the one deliberate
dynamic occurrence in the public timer surface; the typed-catalog guard records
it as its narrow discarded-callable-result policy exception.
Downstream adapter surface: `register_owned_timer` lets an embedding expose the
same contract under its own exact host name and schema -- it takes the owned
call, the callback argument index, and a checked `Duration` plus an optional
repeating `Duration`, and reuses the runtime lookup, callback type/provenance
checks, fresh isolated callback VM, admission limits, backend registration and
rollback of the standard adapters, so `OwnedTimerCallback::new` never needs to
become public. `installed_timer_counts` exposes the installed backend's
synchronous pending/running counts for thin adapter count functions. Both
helpers are name-independent and unit-independent; `timer::at` / `timer::every`
are millisecond adapters over the same path.
The builtin runtime composes the timer surface into the standard catalog, so a
compiled program resolves the imports and each call fails with the documented
installation error until backend state is installed.
The module's own tests cover the callback state machine through the private
callback VM: waiting rounds on independent per-callback bridges, cancellation
of a waiting round, panic and error isolation with recovery for `start` and
for the resumed/polled round, the discarded callback return (no result or
operand accumulates), and overlapping-round rejection.1 parent 769da0b commit 06d206d
3 files changed
Lines changed: 1767 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
47 | 55 | | |
48 | 56 | | |
49 | 57 | | |
| |||
375 | 383 | | |
376 | 384 | | |
377 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
378 | 401 | | |
379 | 402 | | |
380 | 403 | | |
| |||
0 commit comments