diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-17 10:13:13 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-17 10:13:13 +0200 |
| commit | b1b4df39abb41a4ae71733e2d139dc70cc71acd8 (patch) | |
| tree | 3d72b1dd75841e0b950282099ec9c837aa03d869 /src/zilch/Env/future.zig | |
| parent | dd24e86dad0402917b1713d1afeefaf65c3d1e51 (diff) | |
zilch: implement callable and promise
Diffstat (limited to 'src/zilch/Env/future.zig')
| -rw-r--r-- | src/zilch/Env/future.zig | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/zilch/Env/future.zig b/src/zilch/Env/future.zig index 8b88cd8..1b44d85 100644 --- a/src/zilch/Env/future.zig +++ b/src/zilch/Env/future.zig @@ -3,7 +3,7 @@ const Env = @import("root.zig"); const z = @import("../root.zig"); -pub fn Future(comptime kind: Env.Value.Kind) type { +pub fn Future(Kind: type) type { return struct { const Self = @This(); @@ -13,8 +13,8 @@ pub fn Future(comptime kind: Env.Value.Kind) type { return .{ .future = future }; } - pub fn await(self: *const Self, env: *Env) !kind.asType() { - return self.future.await(env, kind); + pub fn await(self: *const Self, env: *Env) !Kind { + return self.future.await(env, Kind); } }; } @@ -29,18 +29,9 @@ pub const AnyFuture = union(enum) { resolved: Env.Value, err: anyerror, - pub fn await(self: *Self, env: *Env, comptime kind: Env.Value.Kind) !kind.asType() { + pub fn await(self: *Self, env: *Env, Kind: type) !Kind { const result = try self.awaitAny(env); - - if (kind != result.kind) { - std.log.err("unexpected {}, expected {}", .{ result.kind, kind }); - @panic("type error"); - } - - return switch (kind) { - .string => result.value.string.ptr[0..result.value.string.len], - else => @field(result.value, @tagName(kind)), - }; + return result.unwrap(Kind); } pub fn awaitAny(self: *Self, env: *Env) !Env.Value { |