Skip to content

Commit 95cae6e

Browse files
Merge pull request #498 from karlseguin/pool_polish
Accommodate zig-js-runtime loop changes
2 parents d12fd78 + 75f66a6 commit 95cae6e

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/html/window.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,20 @@ pub const Window = struct {
128128
if (self.timeoutid >= self.timeoutids.len) return error.TooMuchTimeout;
129129

130130
const ddelay: u63 = delay orelse 0;
131-
const id = loop.timeout(ddelay * std.time.ns_per_ms, cbk);
131+
const id = try loop.timeout(ddelay * std.time.ns_per_ms, cbk);
132132

133133
self.timeoutids[self.timeoutid] = id;
134134
defer self.timeoutid += 1;
135135

136136
return self.timeoutid;
137137
}
138138

139-
pub fn _clearTimeout(self: *Window, loop: *Loop, id: u32) void {
139+
pub fn _clearTimeout(self: *Window, loop: *Loop, id: u32) !void {
140140
// I do would prefer return an error in this case, but it seems some JS
141141
// uses invalid id, in particular id 0.
142142
// So we silently ignore invalid id for now.
143143
if (id >= self.timeoutid) return;
144144

145-
loop.cancel(self.timeoutids[id], null);
145+
try loop.cancel(self.timeoutids[id], null);
146146
}
147147
};

src/http/client.zig

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub const Request = struct {
282282
};
283283
}
284284

285-
loop.connect(AsyncHandlerT, async_handler, &async_handler.read_completion, AsyncHandlerT.connected, socket, address);
285+
try loop.connect(AsyncHandlerT, async_handler, &async_handler.read_completion, AsyncHandlerT.connected, socket, address);
286286
}
287287

288288
// 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 {
490490
}
491491

492492
fn connected(self: *Self, _: *IO.Completion, result: IO.ConnectError!void) void {
493-
self.loop.onConnect(result);
494493
result catch |err| return self.handleError("Connection failed", err);
495494
self.connection.connected() catch |err| {
496495
self.handleError("connected handler error", err);
@@ -518,11 +517,12 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
518517
sent,
519518
self.socket,
520519
node.data,
521-
);
520+
) catch |err| {
521+
self.handleError("loop send error", err);
522+
};
522523
}
523524

524525
fn sent(self: *Self, _: *IO.Completion, n_: IO.SendError!usize) void {
525-
self.loop.onSend(n_);
526526
const n = n_ catch |err| {
527527
return self.handleError("Write error", err);
528528
};
@@ -548,7 +548,9 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
548548
sent,
549549
self.socket,
550550
next_.data,
551-
);
551+
) catch |err| {
552+
self.handleError("loop send error", err);
553+
};
552554
return;
553555
}
554556

@@ -567,18 +569,19 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
567569
}
568570

569571
self.is_receiving = true;
570-
return self.loop.recv(
572+
self.loop.recv(
571573
Self,
572574
self,
573575
&self.read_completion,
574576
Self.received,
575577
self.socket,
576578
self.read_buf[self.read_pos..],
577-
);
579+
) catch |err| {
580+
self.handleError("loop recv error", err);
581+
};
578582
}
579583

580584
fn received(self: *Self, _: *IO.Completion, n_: IO.RecvError!usize) void {
581-
self.loop.onRecv(n_);
582585
self.is_receiving = false;
583586
const n = n_ catch |err| {
584587
return self.handleError("Read error", err);

0 commit comments

Comments
 (0)