Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

serve

WebServer.serve
fn serve(ws: *WebServer) Io.Cancelable!void

File

lib/compiler/Maker/WebServer.zig:212

Code

fn serve(ws: *WebServer) Io.Cancelable!void {
    const graph = ws.graph;
    const io = graph.io;

    var group: Io.Group = .init;
    defer group.cancel(io);

    while (true) {
        var stream = ws.tcp_server.?.accept(io) catch |err| switch (err) {
            error.Canceled => |e| return e,
            else => |e| {
                log.err("failed to accept connection: {t}", .{e});
                return;
            },
        };
        group.concurrent(io, accept, .{ ws, stream }) catch |err| {
            log.err("unable to spawn connection thread: {t}", .{err});
            stream.close(io);
            continue;
        };
    }
}