gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain10f8a8c8Merge branch 'code-order' into mainJukeboxmain/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

  • 10f8a8c8Merge branch 'code-order' into mainJukebox
  • 204fc828Merge branch 'day72' into mainJukebox
  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
  • 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
  • 1f0cd77bMerge branch 'records-day41' into mainJukebox
  • 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
  • 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
  • 04f5d9d5Merge branch 'day41' into mainJukebox
  • 8ed6da45|||PR README: media-player pin df9e7dfmre
  • d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre