From d38e1ffb1533565ecea6dd83cca88d36690fadef Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 26 Oct 2026 17:15:16 +0100 Subject: zilch: implement async --- src/zilch/Promise.zig | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/zilch/Promise.zig') diff --git a/src/zilch/Promise.zig b/src/zilch/Promise.zig index 76362e7..7832b66 100644 --- a/src/zilch/Promise.zig +++ b/src/zilch/Promise.zig @@ -34,8 +34,9 @@ pub inline fn then(self: anytype, env: *Env, func: anytype, ud: *anyopaque) Futu })); } -pub fn as(self: *Self, T: type) *T { - return @ptrCast(self); +pub inline fn await(self: anytype, env: *Env, T: type) !T { + var future = env.call(bindings.await, .{ self }); + return future.await(env, T); } pub const bindings = struct { @@ -47,8 +48,15 @@ pub const bindings = struct { \\ }) \\} ); + + pub const await: Function = .from( + \\async function(promise) { + \\ return promise; + \\} + ); }; pub const functions = [_]Function{ bindings.then, + bindings.await, }; -- cgit v1.2.3-70-g09d2