gitoria

kunibert

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita6577aaea6577aaeRecords: #14 live, #16 startedmrea6577aae/plugins/time/Timer.hl

3.3 KB

  1. \* Timer.hl → class Timer — ONE clock event source, its lifetime, its events.
  2. `every(n)`, `after(n)` and `until(t)` all hand back one of these. The event
  3. loop wiring lives HERE so app code never sees it: the source is registered AT
  4. this instance, the internal fan-out re-emits `tick` at itself, and
  5. `on interval.tick()` in the app is an ordinary instance-scoped handler — the
  6. same shape hl:proc's Process has carried since 2026-08-17.
  7. let interval = every(360)
  8. on interval.tick(t) { … } \\ t = { count, at }
  9. interval.stop()
  10. ONE EVENT NAME FOR ALL THREE. `after(n)` IS `every(n)` that fires once and
  11. `until(t)` IS `after(t - now())`; one primitive, two conveniences. Naming the
  12. one-shot's event `finished` or `isUp` would mean swapping the constructor
  13. forces rewriting the handler, and this language's events are verbs of arrival
  14. — `line`, `exit`, `chunk`, `ready`, `saved`, `tick`. *\
  15. \* The interval this timer was created with, in seconds (raised to hl:time's
  16. floor if it was written below it — see server.hl). *\
  17. Number seconds = 0
  18. \* True for `every()`; false for the one-shots `after()` and `until()`. *\
  19. Boolean repeating = false
  20. \* False once a one-shot has fired or `stop()` was called. An `every` whose
  21. `running` is true keeps the program alive — that is the point of it. *\
  22. Boolean running = false
  23. \* How many ticks have been delivered. 1 on a one-shot's only tick. *\
  24. Number count = 0
  25. Number #id = 0
  26. Number #srcId = 0
  27. \* Arm the timer and register its source. Called by `every`/`after`/`until`;
  28. there is no reason to call it yourself. *\
  29. start(Number secs, Boolean repeat) {
  30. let armed = __native("time.timer", secs, repeat)
  31. #id = armed.id
  32. seconds = secs
  33. repeating = repeat
  34. running = true
  35. #srcId = __native("eventloop.register", armed.events, "__timerTick")
  36. // ONE TICK AT A TIME (ticket #159): a tick handler that waits (a fetch parks its fiber and the
  37. // loop runs the others) is not entered again by this clock; the next tick comes once it returned
  38. // (a LITERAL op, NativeCompile.hl `nativeCall` → hl_eventloop_serial: a computed one would make
  39. // every program importing hl:time, the compiler too, link dynamic — ticket #165)
  40. __native("eventloop.serial", #srcId)
  41. return this
  42. }
  43. on __timerTick(ev) {
  44. count = ev.count
  45. if (repeating == false) {
  46. // A SPENT ONE-SHOT RETIRES ITS SOURCE, BEFORE the tick is emitted.
  47. // Mission 249 found the same defect in hl:proc on 2026-08-29: a child
  48. // that had exited left its source registered, so the loop still held
  49. // something that would never speak again and NO hl:proc program could
  50. // ever end. An `after()` that does not retire hangs every program that
  51. // uses one, which is why the test for this asserts TERMINATION and not
  52. // output.
  53. running = false
  54. __native("eventloop.unregister", #srcId)
  55. __native("time.timer_stop", #id)
  56. }
  57. emit tick(ev)
  58. return null
  59. }
  60. \* Stop an interval (and end the program, if it was the only thing keeping it
  61. alive) — the counterpart of `server.kill()`. True when this call was the one
  62. that stopped it; false if it had already fired or been stopped. *\
  63. stop() {
  64. if (running == false) {
  65. return false
  66. }
  67. running = false
  68. // ORDER IS LOAD-BEARING: retire the source first, so the loop has dropped
  69. // this fd from its epoll set before the fd is closed.
  70. __native("eventloop.unregister", #srcId)
  71. __native("time.timer_stop", #id)
  72. return true
  73. }

Branches

Latest commits

  • a6577aaeRecords: #14 live, #16 startedmre
  • 0382238bStart fresh on Review again and name vendored pathsKunibert
  • 5608c6f1Records: kunibert#13 vendored paths livemre
  • 8840771dExclude vendored findings from app verdictsKunibert
  • 6aa65353Records: jukebox connected, first reviewmre
  • ad8011cfRecords: neutral ticket rule, jukeboxmre
  • ca5f31dfPrompt: neutral reviewer identitymre
  • b241d9c8Records: Anton tryParse noteKunibert
  • 42cc1bc0Records: K12 doneKunibert
  • 9e6039eeRecords: gates K11, K12Kunibert
  • 59b8fe83Use Hybriel day39 helpersKunibert
  • c2e393a2Records: K12 startedKunibert
  • 00696678Records: Anton day39 notemre
  • 070e01a4Records: parkmre
  • bf8af0dcRecords: v1.4 checkedmre
  • 44af321bRecords: contract v1.4mre
  • 310f3fd0Records: outdated semanticsmre
  • 268ebfe6Records: #11 proven live and closedmre
  • 88e8aad3Records: K11 verified and deployedmre
  • cd4cb09cNo review and status error when the model's tools did not run (kunibert#11)Kunibert