diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-12-09 12:25:57 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-12-09 15:27:26 -0500 |
| commit | f205d23e650019dd66120cf122ffb449267f619b (patch) | |
| tree | 1d7ab12881bcf381ab46dfdf21653fc690ee44fc /lib/std | |
| parent | 69b587c1d389808e55846cadd8eec5b9fd4bc64a (diff) | |
| download | zig-f205d23e650019dd66120cf122ffb449267f619b.tar.gz zig-f205d23e650019dd66120cf122ffb449267f619b.zip | |
implement async function call with `@call`
this removes the last usage of var args in zig std lib
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/builtin.zig | 3 | ||||
| -rw-r--r-- | lib/std/event/group.zig | 9 |
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index b3a80dc317..4c57915f92 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -382,6 +382,9 @@ pub const CallOptions = struct { /// Equivalent to function call syntax. auto, + /// Equivalent to async keyword used with function call syntax. + async_kw, + /// Prevents tail call optimization. This guarantees that the return /// address will point to the callsite, as opposed to the callsite's /// callsite. If the call is otherwise required to be tail-called diff --git a/lib/std/event/group.zig b/lib/std/event/group.zig index 9feb99148b..d9076ef78d 100644 --- a/lib/std/event/group.zig +++ b/lib/std/event/group.zig @@ -60,16 +60,19 @@ pub fn Group(comptime ReturnType: type) type { /// allocated by the group and freed by `wait`. /// `func` must be async and have return type `ReturnType`. /// Thread-safe. - pub fn call(self: *Self, comptime func: var, args: ...) error{OutOfMemory}!void { - var frame = try self.allocator.create(@Frame(func)); + pub fn call(self: *Self, comptime func: var, args: var) error{OutOfMemory}!void { + var frame = try self.allocator.create(@typeOf(@call(.{ .modifier = .async_kw }, func, args))); + errdefer self.allocator.destroy(frame); const node = try self.allocator.create(AllocStack.Node); + errdefer self.allocator.destroy(node); node.* = AllocStack.Node{ .next = undefined, .data = Node{ - .handle = @asyncCall(frame, {}, func, args), + .handle = frame, .bytes = std.mem.asBytes(frame), }, }; + frame.* = @call(.{ .modifier = .async_kw }, func, args); self.alloc_stack.push(node); } |
