Accommodate zig-js-runtime loop changes

This commit is contained in:
Karl Seguin
2025-03-31 14:59:40 +08:00
parent 82e67b7550
commit 75f66a6cb2
3 changed files with 15 additions and 12 deletions

View File

@@ -128,7 +128,7 @@ pub const Window = struct {
if (self.timeoutid >= self.timeoutids.len) return error.TooMuchTimeout;
const ddelay: u63 = delay orelse 0;
const id = loop.timeout(ddelay * std.time.ns_per_ms, cbk);
const id = try loop.timeout(ddelay * std.time.ns_per_ms, cbk);
self.timeoutids[self.timeoutid] = id;
defer self.timeoutid += 1;
@@ -136,12 +136,12 @@ pub const Window = struct {
return self.timeoutid;
}
pub fn _clearTimeout(self: *Window, loop: *Loop, id: u32) void {
pub fn _clearTimeout(self: *Window, loop: *Loop, id: u32) !void {
// I do would prefer return an error in this case, but it seems some JS
// uses invalid id, in particular id 0.
// So we silently ignore invalid id for now.
if (id >= self.timeoutid) return;
loop.cancel(self.timeoutids[id], null);
try loop.cancel(self.timeoutids[id], null);
}
};

View File

@@ -282,7 +282,7 @@ pub const Request = struct {
};
}
loop.connect(AsyncHandlerT, async_handler, &async_handler.read_completion, AsyncHandlerT.connected, socket, address);
try loop.connect(AsyncHandlerT, async_handler, &async_handler.read_completion, AsyncHandlerT.connected, socket, address);
}
// Does additional setup of the request for the firsts (i.e. non-redirect) call.
@@ -490,7 +490,6 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
}
fn connected(self: *Self, _: *IO.Completion, result: IO.ConnectError!void) void {
self.loop.onConnect(result);
result catch |err| return self.handleError("Connection failed", err);
self.connection.connected() catch |err| {
self.handleError("connected handler error", err);
@@ -518,11 +517,12 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
sent,
self.socket,
node.data,
);
) catch |err| {
self.handleError("loop send error", err);
};
}
fn sent(self: *Self, _: *IO.Completion, n_: IO.SendError!usize) void {
self.loop.onSend(n_);
const n = n_ catch |err| {
return self.handleError("Write error", err);
};
@@ -548,7 +548,9 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
sent,
self.socket,
next_.data,
);
) catch |err| {
self.handleError("loop send error", err);
};
return;
}
@@ -567,18 +569,19 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
}
self.is_receiving = true;
return self.loop.recv(
self.loop.recv(
Self,
self,
&self.read_completion,
Self.received,
self.socket,
self.read_buf[self.read_pos..],
);
) catch |err| {
self.handleError("loop recv error", err);
};
}
fn received(self: *Self, _: *IO.Completion, n_: IO.RecvError!usize) void {
self.loop.onRecv(n_);
self.is_receiving = false;
const n = n_ catch |err| {
return self.handleError("Read error", err);