We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to implement a xselect like how it works on go/ may in Rust, and find that the current channel only support spsc.
pub fn xselect(tuples: anytype) !void { var chan = SelectChan.init(null); defer chan.close(); comptime var idx: usize = 0; inline for (tuples) |tuple| { const Gen = struct { const Self = @This(); func: @TypeOf(tuple[0]), args: @TypeOf(tuple[1]), cb: @TypeOf(tuple[2]), fn run(self: Self, _chan: *SelectChan, _idx: usize) anyerror!void { const ret = if (@typeInfo(@TypeOf(self.func)).Fn.return_type == std.builtin.Type.ErrorUnion) try @call(.always_inline, self.func, self.args) else @call(.always_inline, self.func, self.args); try _chan.send(_idx); @call(.always_inline, self.cb, .{ret}); } }; const _gen: Gen = .{ .func = tuple[0], .args = tuple[1], .cb = tuple[2] }; _ = try xasync(Gen.run, .{ _gen, &chan, idx }, tuple[3]); idx += 1; } _ = chan.recv(); return; }
fn selecMain() !void { const stack_size: usize = 1024 * 16; const stack1 = try libcoro.stackAlloc(env.allocator, stack_size); defer env.allocator.free(stack1); const stack2 = try libcoro.stackAlloc(env.allocator, stack_size); defer env.allocator.free(stack2); try aio.xselect(.{ .{ add, .{ @as(u32, 1), @as(u32, 2) }, report_add, stack1 }, .{ sub, .{ @as(u32, 1), @as(u32, 1) }, report_sub, stack2 } }); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Try to implement a xselect like how it works on go/ may in Rust, and find that the current channel only support spsc.
The text was updated successfully, but these errors were encountered: