diff options
author | 2022-10-09 00:49:45 -0700 | |
---|---|---|
committer | 2022-10-09 02:02:47 -0700 | |
commit | 4dbbdb1671d44eae553b4d8a2e352c03c0050fa6 (patch) | |
tree | 975c6098bde04fa6eadb09066be190dcdf5f5413 /src/bun.js/javascript.zig | |
parent | 4b5c9acc72908ba22e3f708c4df59c6316e4846b (diff) | |
download | bun-4dbbdb1671d44eae553b4d8a2e352c03c0050fa6.tar.gz bun-4dbbdb1671d44eae553b4d8a2e352c03c0050fa6.tar.zst bun-4dbbdb1671d44eae553b4d8a2e352c03c0050fa6.zip |
Clean up how we reload entry point a little
Diffstat (limited to 'src/bun.js/javascript.zig')
-rw-r--r-- | src/bun.js/javascript.zig | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 34cd0610d..8fccee097 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -384,7 +384,7 @@ pub const VirtualMachine = struct { pub fn reload(this: *VirtualMachine) void { Output.debug("Reloading...", .{}); this.global.reload(); - this.pending_internal_promise = this.loadEntryPoint(this.main) catch @panic("Failed to reload"); + this.pending_internal_promise = this.reloadEntryPoint(this.main) catch @panic("Failed to reload"); } pub fn io(this: *VirtualMachine) *IO { @@ -1474,7 +1474,7 @@ pub const VirtualMachine = struct { this.global.deleteModuleRegistryEntry(&str); } - pub fn loadEntryPoint(this: *VirtualMachine, entry_path: string) !*JSInternalPromise { + pub fn reloadEntryPoint(this: *VirtualMachine, entry_path: []const u8) !*JSInternalPromise { this.main = entry_path; try this.entry_point.generate(this.bun_watcher != null, Fs.PathName.init(entry_path), main_file_name); this.eventLoop().ensureWaker(); @@ -1500,7 +1500,29 @@ pub const VirtualMachine = struct { this.pending_internal_promise = promise; } - this.waitForPromise(promise); + return promise; + } + + pub fn loadEntryPoint(this: *VirtualMachine, entry_path: string) !*JSInternalPromise { + var promise = try this.reloadEntryPoint(entry_path); + + // pending_internal_promise can change if hot module reloading is enabled + if (this.bun_watcher != null) { + switch (this.pending_internal_promise.status(this.global.vm())) { + JSC.JSPromise.Status.Pending => { + while (this.pending_internal_promise.status(this.global.vm()) == .Pending) { + this.eventLoop().tick(); + + if (this.pending_internal_promise.status(this.global.vm()) == .Pending) { + this.eventLoop().autoTick(); + } + } + }, + else => {}, + } + } else { + this.waitForPromise(promise); + } this.eventLoop().autoTick(); |