gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit06565b1f06565b1fRecords: day35 relay note, tickets subscription idmre06565b1f/plugins/fetch/pending_fetch.hl

4.0 KB

  1. \* A request in flight. Handed back by fetch()/fetchStart() — never `new`ed.
  2. The request is already on the wire when you hold one: it has a thread of
  3. its own, holding one costs a socket, not a fiber. With stream = true the
  4. events below arrive AT this object. *\
  5. \* A decoded piece of the body, token by token (stream mode). *\
  6. emit chunk(
  7. String chunk \\ the decoded bytes as they arrived
  8. )
  9. \* The stream's final frame — body is EMPTY, the chunks were the body. *\
  10. emit done(
  11. Number status \\ the HTTP status
  12. Boolean ok \\ true for 2xx
  13. Hybrid headers \\ response headers
  14. String error \\ '' or the failure text
  15. Boolean aborted \\ true when abort() cut it
  16. )
  17. Hybrid #handle
  18. Number #srcId = 0
  19. // Has the answer arrived? Never waits — a poll for code that wants to do
  20. // something else in the meantime.
  21. done() {
  22. return #handle.done()
  23. }
  24. // THE WAIT. Blocks the calling fiber until the answer is in, then hands back a
  25. // FetchResponse. A failed fetch (refused connection, timeout, TLS verification,
  26. // too many redirects) surfaces here as a located error routed to `on Error`, so
  27. // a caller that wants to survive one writes an `on Error(e)` handler.
  28. response() {
  29. // Not in yet: let the sibling fibers (a `concurrent` group, the loop's other
  30. // handlers) run instead of blocking the thread on this socket. On the process
  31. // stack there is no one to yield to and result() is the wait.
  32. // The yield names the fetch's bell (an eventfd rung when it is done): a
  33. // `concurrent` group whose arms ALL wait sleeps on those, not on a timer.
  34. let bell = #handle.doneFd()
  35. while (!#handle.done()) {
  36. if (!__native("fiber.yield", bell)) { break }
  37. }
  38. let r = #handle.result()
  39. // An `on Error` handler that ABSORBED the failure leaves the call yielding
  40. // null (the plugin-error contract every `hl:` module follows). Hydrating null
  41. // would be a second, misleading error, so a caught failure answers null —
  42. // exactly what `hl:fs`'s file() does.
  43. if (r == null) {
  44. return null
  45. }
  46. return r > new FetchResponse()
  47. }
  48. // STREAM MODE (the LLM-token flow). `fetch(url, { stream = true })` calls this
  49. // before handing the instance out: the ticket's own event source is registered
  50. // AT this instance and the fan-out below re-emits every frame at itself, so app
  51. // code holds nothing but the object and its events — `on p.chunk`, `on p.done`.
  52. arm() {
  53. #srcId = __native("eventloop.register", #handle.events(), "__fetchEvent")
  54. }
  55. // THE FAN-OUT: a native frame in, a DECLARED event out. The frames are Hybrids
  56. // ({ tag, url, chunk } or { tag, url, status, ok, body, error, headers, aborted });
  57. // `chunk` and `done` above declare TYPED parameters, so each field is handed over
  58. // BY NAME — `emit chunk(ev)` would bind a Hybrid to `String chunk` and fail every
  59. // frame (mission 257: it did).
  60. //
  61. // NAMED, NOT POSITIONAL, and that distinction cost the creator a night (2026-08-30).
  62. // 257 fixed the Hybrid-into-String bind by emitting POSITIONALLY — `emit
  63. // chunk(ev.chunk)` — which type-checks and is still wrong: every handler in this
  64. // language receives a PAYLOAD OBJECT and destructures it. His own working code is
  65. // `on stream.chunk({ chunk })`, exactly as `on server.line({ line, stream })` reads
  66. // for hl:proc and as his `emit ready(port = …)` writes it. Positional emission
  67. // hands `{ chunk }` a String, and the app dies with "Cannot destructure non-object
  68. // value" — a DIFFERENT error from the one 257 fixed, on the same line of his app.
  69. // `name = value` is the form that satisfies the typed declaration AND keeps
  70. // destructuring working. Do not "simplify" it back.
  71. on __fetchEvent(ev) {
  72. if (ev.chunk != null) {
  73. emit chunk(chunk = ev.chunk)
  74. return null
  75. }
  76. // the final frame — retire the source so the loop can end by itself
  77. __native("eventloop.unregister", #srcId)
  78. emit done(status = ev.status, ok = ev.ok, headers = ev.headers, error = ev.error, aborted = ev.aborted)
  79. return null
  80. }
  81. \* THE STOP BUTTON: abort this fetch — the socket is shut down, the peer
  82. sees the disconnect and stops generating, and `done` arrives with
  83. aborted = true. (fetchAbort(tag) cuts a whole tag at once.) *\
  84. abort() {
  85. return #handle.abort()
  86. }

Branches

Latest commits

  • 06565b1fRecords: day35 relay note, tickets subscription idmre
  • c6dc3e86RV28b: switch to set day35mre
  • 24e401b8Tracker: TR7 watch cleanmre
  • b0412957Tracker: RV28b handed overmre
  • 456940c8Tracker: RULINGS pathmre
  • b87a8fdcTracker: worldapi-conductor paths backmre
  • 641f3b54Tracker: Apollo answermre
  • 8b3cbddaTracker: status, TR7 fix livemre
  • ec30162aTracker: TR7 fix livemre
  • 54cbec80compose: ignore SIGPIPE (TR7 crash loop, exit 141)mre
  • 3e164b63Tracker: status after CL1mre
  • 9d686bb3Tracker: CL1 reviewedmre
  • b8bba562CL1: crash loop report (SIGPIPE confirmed, trap wrapper option)mre
  • 298785f2Tracker: CL1 startedmre
  • 36b22710Tracker: port slot, CL1 briefmre
  • a401190fTracker: GO for the crash loopmre
  • e195d372Tracker: token pathsmre
  • 7f541d11Tracker conductor: CONDUCTOR.md, short STATUS.md, old status + decisions archive to archive/2026-10-31mre
  • 8dd423f7README: login.js stays by caramboleyo's explicit rulemre
  • d8df1493tracker: standby service on port 45018 and a gap-free hand-over in deploy.sh step 4mre