gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6e03be0a6e03be0apull state: keep the resync marker until the sync ran (#56)mre6e03be0a/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

  • 6e03be0apull state: keep the resync marker until the sync ran (#56)mre
  • 93bdd26cpull state: wait for a claimed row, resync when it stays busy (#56)mre
  • e53d284bpull state: stop on a failed branch scan, claim the row on writes (#56)mre
  • d8608224close and reopen: keep a manual close against sync (#56)mre
  • ffb60746|||PR close and reopen pull requests (#56)mre
  • fe209ffeMerge branch 'w56-owner-members' into mainGitoria
  • fa0754c8|||PR repository owner transfer and members API (#55)mre
  • 8862e537Merge branch 'w55-rename-org' into mainGitoria
  • 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
  • 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria