fork_server
def fork_server(var srv: HttpServer, handler: def(Request) raises thin -> Response, startup_us: Int = Int(150000)) -> Int Fork a child, run srv.serve(handler) in it, return the child PID to the parent after a brief startup wait.
The bare-function overload. For Handler-struct shapes use
the parametric overload below.
- Args
srv: A boundHttpServer(the parent readssrv.local_addr()before the call so it knows the port). Moved into the child via the standardfork(2)semantics; the parent's reference is consumed.handler: The samedef(Request) raises -> ResponseshapeHttpServer.serveaccepts.startup_us: Microseconds the parent sleeps after the fork so the child has time to enterserve(). Default 150 ms covers the slowest CI runners.
Raises Error: If fork(2) fails. Failures inside the child's
serve() are swallowed (the child _exits); the
parent only ever sees the PID.
def fork_server[H: Handler](var srv: HttpServer, var handler: H, startup_us: Int = Int(150000)) -> Int Fork-and-serve overload for Handler-struct shapes.
Identical semantics to the bare-function overload; this one
exists so Router, middleware wrappers, and
user-defined Handler structs can flow through the helper
without an FnHandler shim. Copyable is not required
-- the child process runs the single-worker HttpServer.serve
path, which only needs Handler.
- Args
srv: A boundHttpServer. Moved into the child.handler: AnyHandlerstruct.startup_us: Parent-side startup sleep (microseconds).
Raises Error: If fork(2) fails.