gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9f3516999f351699Preserve comments and nest supported selectors without changing rendered outputmre9f351699/plugins/fetch/pending_fetch.hl

4.3 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. }
  87. // Same wait as response(), with the native failure kept as an ordinary Hybrid.
  88. tryResponse() {
  89. bell = #handle.doneFd()
  90. while (!#handle.done()) {
  91. if (!__native("fiber.yield", bell)) { break }
  92. }
  93. r = #handle.tryResult()
  94. if (r.status == 0) { return r }
  95. return r > new FetchResponse()
  96. }

Branches

Latest commits

  • 9f351699Preserve comments and nest supported selectors without changing rendered outputmre
  • 97110ad9WIP: nest accepted layout selectors; stopped at startup parse failuremre
  • ce4a0baeKeep caller slot styles whole so minimal shell apps startmre
  • 12cd3992Re-vendor complete Hybriel plugins and runtime to day44mre
  • b05c20feBackup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 8d9ed0b8Re-vendor complete Hybriel plugins and runtime to day39mre
  • ebd00b6cNest caller slot styles in three-panemre
  • 009991efNest caller slot styles in list-firstmre
  • 494d75d4Nest caller slot styles in app-sidebarmre
  • e5571680Align all plugin sources with Hybriel day38bmre
  • 5d204c46Re-vendor layouts to Hybriel set day38bmre
  • 17e0f03eNest html-prefixed theme component overridesmre
  • e54e735eFormat plain theme elements with nested rules and bare mediamre
  • 547f834eRecord LY7 deployment and live verificationmre
  • fa4600b1Link caller-slot style exceptions to hybriel#270mre
  • 413b11e1Record corrected LY7 nesting, exact CSS and Chrome proofmre
  • b810453etracker-demo: nest child and compound selectors in Stylemre
  • 0b5b1d61notes-demo: nest child and compound selectors in Stylemre
  • ab22bdc2mail-demo: nest child and compound selectors in Stylemre
  • fe2d8de9home: nest child and compound selectors in Stylemre