gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit273494e2273494e2STATUS rewrittenmre273494e2/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

  • 273494e2STATUS rewrittenmre
  • 227c9b96Records: jb19 livemre
  • 9f365376README: the bar's controls (jb19)mre
  • d18851fdjb19: pressed switches look different (whole selector), queue column cannot widen past the panel, gates follow the new bar (jb3, jb11, jb15)mre
  • 82b54c0ejb19: bar Shuffle · Previous · Play · Next · Repeat, no 10 s buttons; Shuffle switch (shuffle from the playing song, back to the list), Repeat off/all/one, both remembered in ui.json; Shuffle my favourites an ordinary button; gate tests/jb19.mjsmre
  • ba354710jb19: icons pinned to components.hybriel 46fefaa (shuffle, repeat, repeatOne, prevTrack, nextTrack)mre
  • d8e8d059jb19 step 2: media-player from components.hybriel c96709c (skip, repeat options; the end of a song only calls onPlay), sync-components.sh and SOURCE point to it, jb11 counts media loads and metadata writes (from jb21 d3a026e)mre
  • 7b048c1bRecords: jb19 done, L2 live stepmre
  • 665185aeMission 009: jb19 livemre
  • 47b2d3beRecords: P1 resumedmre
  • 8e326e94Records: resetKey blockedmre
  • f72dd7edRecords: icons comingmre
  • b264e5deRecords: P1 icons stopmre
  • 514d7cbeRecords: mission 008 startedmre
  • 61c40127Mission 008: #19 + #21mre
  • 6dcaeb46Records: resetKey planmre
  • c5dbf2ecRecords: R2 resultmre
  • 956069b8Records: R1 result, mission 007mre
  • 3c8a2e12Mission 007: #20 sort scrollmre
  • deb8cef5Records: mission 006 startedmre