diff options
| author | 2022-12-02 01:56:12 -0800 | |
|---|---|---|
| committer | 2022-12-02 01:56:12 -0800 | |
| commit | 8eddfc61a83657c770833665a0fb9926aa326603 (patch) | |
| tree | ccb130aeb8664e0fa1800750eb7e66a11179399b /src/bun.js/event_loop.zig | |
| parent | 37525db5cf2b8b609bd16cc9cfa0c80aa80f9f00 (diff) | |
| download | bun-8eddfc61a83657c770833665a0fb9926aa326603.tar.gz bun-8eddfc61a83657c770833665a0fb9926aa326603.tar.zst bun-8eddfc61a83657c770833665a0fb9926aa326603.zip | |
Add generic way to block on a promise
Diffstat (limited to 'src/bun.js/event_loop.zig')
| -rw-r--r-- | src/bun.js/event_loop.zig | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 7fe248dad..0e2d16486 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -521,7 +521,18 @@ pub const EventLoop = struct { } // TODO: fix this technical debt - pub fn waitForPromise(this: *EventLoop, promise: *JSC.JSInternalPromise) void { + pub fn waitForPromise(this: *EventLoop, promise: anytype) void { + return waitForPromiseWithType(this, std.meta.Child(@TypeOf(promise)), promise); + } + + pub fn waitForPromiseWithType(this: *EventLoop, comptime Promise: type, promise: *Promise) void { + comptime { + switch (Promise) { + JSC.JSPromise, JSC.JSInternalPromise => {}, + else => @compileError("Promise must be a JSPromise or JSInternalPromise, received: " ++ @typeName(Promise)), + } + } + switch (promise.status(this.global.vm())) { JSC.JSPromise.Status.Pending => { while (promise.status(this.global.vm()) == .Pending) { |
