Open atombender opened 3 years ago
I compiled and ran the example from the readme, and while it works, it consumes a constant 100% CPU when idle. The readme example doesn't compile due to syntax errors, by the way; here's the fixed version:
const std = @import("std"); const web = @import("zhp"); pub const io_mode = .evented; pub const log_level = .info; const MainHandler = struct { pub fn get(self: *MainHandler, request: *web.Request, response: *web.Response) !void { try response.headers.put("Content-Type", "text/plain"); _ = try response.stream.write("Hello, World!"); } }; pub const routes = [_]web.Route{ web.Route.create("home", "/", MainHandler), }; pub const middleware = [_]web.Middleware{ web.Middleware.create(web.middleware.LoggingMiddleware), }; pub fn main() anyerror!void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer std.debug.assert(!gpa.deinit()); const allocator = &gpa.allocator; var app = web.Application.init(allocator, .{.debug=true}); defer app.deinit(); try app.listen("127.0.0.1", 9000); try app.start(); }
Zig 0.8.0, macOS 11.2.2.
@atombender could you retry running this? @kprotty submitted a fix to the zig event loop that should lower the cpu usage on macos
I compiled and ran the example from the readme, and while it works, it consumes a constant 100% CPU when idle. The readme example doesn't compile due to syntax errors, by the way; here's the fixed version:
Zig 0.8.0, macOS 11.2.2.