hybriel
hl:proc: no blocking run for server-rendered pages
opened by Architect · assigned to Caramboleyo
opened · updated
A page component is built synchronously on the server, but hl:proc only reports a program's output through events, so git output (README, file list, releases) cannot be in the first HTML of gitoria's pages.
Expected: a blocking call like fetch's, e.g. run(argv, { cwd, timeout }) → { exit, lines } (or Bytes), usable while a page renders.
Details: found in gitoria#16 (drop host.js, pages rendered on the server). Also: a component has no "mounted" hook; an emit server from the run body goes out before the socket opens, so a pushed answer can be lost.
History
Architect opened the ticket Anton changed the state progress Taken (mission 325, Worker A, after 12:00):
run(argv, { cwd, timeout })→{ exit, lines }, blocking like fetch; and an emit from the run body is queued until the socket opens instead of being lost.Anton changed the state review Done:
run()in hl:proc waits for a program and returns its output. Anemit serverin a component's root now gets its pushed answer on the page (commit 0b6557af on branch tickets-b, which lands on master when it is merged).Test:
- In a page component, write
import { run } from 'hl:proc'andfiles = run(['git', 'ls-files'], { cwd = '.', timeout = 5 }).lines, and showfilesin the View. The first HTML of the page (view source) contains the file list. - In the same component's root, write
emit server ping(). Addon server ping() { emit client pong('x') }andon client pong(t) { answer = t }. The page showsx, both on a fresh load and after navigating to the page by a link.
Details:
run()returns{ exit, lines, stderr }. Withbinary = true,data(Bytes) replaceslines. The options arecwd,env,binaryandtimeoutin seconds. When the timeout runs out, the program is killed and the call fails with an error. The program gets no input (stdin is empty).- The root's emit still goes out right away (over POST, because the socket opens later). The answer is held until the page is on screen.
- In a page component, write
Anton commented Correction: the commit is 3cc66a51 (it was amended to include the rebuilt hl:proc library), not 0b6557af.
Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name.