clean up Promise handling (#1697)

This commit is contained in:
Alex Lam S.L
2023-01-02 02:37:45 +02:00
committed by GitHub
parent 2345e268bc
commit 8a29c64302
14 changed files with 127 additions and 162 deletions

View File

@@ -571,7 +571,7 @@ pub const VirtualMachine = struct {
this.eventLoop().tick();
}
pub fn waitForPromise(this: *VirtualMachine, promise: anytype) void {
pub fn waitForPromise(this: *VirtualMachine, promise: JSC.AnyPromise) void {
this.eventLoop().waitForPromise(promise);
}
@@ -1308,7 +1308,9 @@ pub const VirtualMachine = struct {
if (this.node_modules != null and !this.has_loaded_node_modules) {
this.has_loaded_node_modules = true;
promise = JSModuleLoader.loadAndEvaluateModule(this.global, ZigString.static(bun_file_import_path));
this.waitForPromise(promise);
this.waitForPromise(JSC.AnyPromise{
.Internal = promise,
});
if (promise.status(this.global.vm()) == .Rejected)
return promise;
}
@@ -1343,7 +1345,9 @@ pub const VirtualMachine = struct {
}
} else {
this.eventLoop().performGC();
this.waitForPromise(promise);
this.waitForPromise(JSC.AnyPromise{
.Internal = promise,
});
}
this.eventLoop().autoTick();
@@ -1390,7 +1394,9 @@ pub const VirtualMachine = struct {
var promise: *JSInternalPromise = undefined;
promise = JSModuleLoader.loadAndEvaluateModule(this.global, &ZigString.init(entry_path));
this.waitForPromise(promise);
this.waitForPromise(JSC.AnyPromise{
.Internal = promise,
});
return promise;
}
@@ -2032,7 +2038,9 @@ pub const EventListenerMixin = struct {
vm.tick();
var promise = JSInternalPromise.resolvedPromise(vm.global, result);
vm.event_loop.waitForPromise(promise);
vm.event_loop.waitForPromise(JSC.AnyPromise{
.Internal = promise,
});
if (fetch_event.rejected) return;