diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-26 17:15:16 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-26 17:15:16 +0100 |
| commit | d38e1ffb1533565ecea6dd83cca88d36690fadef (patch) | |
| tree | 4946ffec374d8d0353a909b2ae314b81cbf07031 /src/zilch/Promise.zig | |
| parent | 8dd8f96b24710dc4f2d29065928244a40a432379 (diff) | |
zilch: implement async
Diffstat (limited to 'src/zilch/Promise.zig')
| -rw-r--r-- | src/zilch/Promise.zig | 12 |
1 files changed, 10 insertions, 2 deletions
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, }; |