Leveraging Zig's Allocators
Let's say we wanted to write an HTTP server library for Zig. At the core of this library, we might have a pool of threads to handle requests. Keeping things simple, it might look something like:
fn run(worker: *Worker) void {
while (queue.pop()) |conn| {
const action = worker.route(conn.req.url);
action(conn.req, conn.res) catch { // TODO: 500 };
worker.write(conn.res);
}
}
As a user of this library, a sample action might be:
fn greet(req: *http.Request, res: *http.Response) void {
res.status = ...
Read more at openmymind.net