Skip to content

Commit

Permalink
update tigerbeetle-io
Browse files Browse the repository at this point in the history
  • Loading branch information
krichprollsch committed Feb 11, 2025
1 parent f40f491 commit cb87276
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 47 deletions.
48 changes: 3 additions & 45 deletions src/loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -166,52 +166,10 @@ pub const SingleThreaded = struct {
js_cbk: ?JSCallback,
};

fn cancelCallback(
ctx: *ContextCancel,
completion: *IO.Completion,
result: IO.CancelError!void,
) void {
defer ctx.loop.freeCbk(completion, ctx);

const old_events_nb = ctx.loop.removeEvent();
if (builtin.is_test) {
report("cancel done, remaining events: {d}", .{old_events_nb - 1});
}

// TODO: return the error to the callback
result catch |err| {
switch (err) {
error.NotFound => log.debug("cancel callback: {any}", .{err}),
else => log.err("cancel callback: {any}", .{err}),
}
return;
};

// js callback
if (ctx.js_cbk) |js_cbk| {
defer js_cbk.deinit(ctx.loop.alloc);
js_cbk.call(null) catch {
ctx.loop.cbk_error = true;
};
}
}

pub fn cancel(self: *Self, id: usize, js_cbk: ?JSCallback) void {
pub fn cancel(self: *Self, id: usize) void {
const comp_cancel: *IO.Completion = @ptrFromInt(id);

const completion = self.alloc.create(IO.Completion) catch unreachable;
completion.* = undefined;
const ctx = self.alloc.create(ContextCancel) catch unreachable;
ctx.* = ContextCancel{
.loop = self,
.js_cbk = js_cbk,
};

const old_events_nb = self.addEvent();
self.io.cancel(*ContextCancel, ctx, cancelCallback, completion, comp_cancel);
if (builtin.is_test) {
report("cancel {d}", .{old_events_nb + 1});
}
self.io.cancel(comp_cancel);
_ = self.removeEvent();
}

// IO callbacks APIs
Expand Down
2 changes: 1 addition & 1 deletion src/tests/cbk_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub const Window = struct {

pub fn _cancel(self: Window, loop: *jsruntime.Loop, id: u32) void {
if (id >= self.timeoutid) return;
loop.cancel(self.timeoutids[id], null);
loop.cancel(self.timeoutids[id]);
}

pub fn _cbkAsyncWithNatArg(_: Window, callback: Callback) !void {
Expand Down
2 changes: 1 addition & 1 deletion vendor/tigerbeetle-io

0 comments on commit cb87276

Please sign in to comment.