aboutsummaryrefslogtreecommitdiff
path: root/src/zeroscript/Env/future.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/zeroscript/Env/future.zig')
-rw-r--r--src/zeroscript/Env/future.zig59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/zeroscript/Env/future.zig b/src/zeroscript/Env/future.zig
deleted file mode 100644
index a014990..0000000
--- a/src/zeroscript/Env/future.zig
+++ /dev/null
@@ -1,59 +0,0 @@
-const std = @import("std");
-const Env = @import("root.zig");
-const z = @import("../root.zig");
-
-
-pub fn Future(comptime kind: Env.Value.Kind) type {
- return struct {
- const Self = @This();
-
- future: AnyFuture,
-
- pub fn fromAny(future: AnyFuture) Self {
- return .{ .future = future };
- }
-
- pub fn await(self: *const Self, env: *Env) !kind.asType() {
- return self.future.await(env, kind);
- }
- };
-}
-
-pub const AnyFuture = union(enum) {
- const Self = @This();
-
- result: *Env.Value,
- err: anyerror,
-
- pub fn await(self: *const Self, env: *Env, comptime kind: Env.Value.Kind) !kind.asType() {
- const result = try self.awaitAny(env);
-
- if (kind != result.kind) {
- std.log.err("unexpected {}, expected {}", .{ result.kind, kind });
- @panic("type error");
- }
-
- return switch (kind) {
- .uninit => @panic("uninitialized result"),
- .string => result.value.string.ptr[0..result.value.string.len],
- else => @field(result.value, @tagName(kind)),
- };
- }
-
- pub fn awaitAny(self: *const Self, env: *Env) !Env.Value {
- switch (self.*) {
- .err => |err| return err,
- .result => |result| {
- defer env.pool.destroy(result);
-
- if (result.kind != .uninit) {
- return result.*;
- }
-
- env.flush();
-
- return result.*;
- }
- }
- }
-};