diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/event_loop.zig | 26 | ||||
-rw-r--r-- | src/bun.js/javascript.zig | 28 |
2 files changed, 51 insertions, 3 deletions
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 462136414..331d939e2 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -278,6 +278,8 @@ pub const EventLoop = struct { var transform_task: *HotReloadTask = task.get(HotReloadTask).?; transform_task.*.run(); transform_task.deinit(); + // special case: we return + return 0; }, @field(Task.Tag, typeBaseName(@typeName(AnyTask))) => { var any: *AnyTask = task.get(AnyTask).?; @@ -486,6 +488,13 @@ pub const Poller = struct { loader.onReady(@bitCast(i64, kqueue_event.data)); }, + @field(Pollable.Tag, "BufferedOutput") => { + var loader = ptr.as(JSC.Subprocess.BufferedOutput); + + loader.poll_ref.deactivate(loop); + + loader.ready(@bitCast(i64, kqueue_event.data)); + }, @field(Pollable.Tag, "FileSink") => { var loader = ptr.as(JSC.WebCore.FileSink); loader.poll_ref.deactivate(loop); @@ -524,6 +533,21 @@ pub const Poller = struct { loader.onPoll(0, 0); }, + + @field(Pollable.Tag, "BufferedInput") => { + var loader = ptr.as(JSC.Subprocess.BufferedInput); + + loader.poll_ref.deactivate(loop); + + loader.onReady(0); + }, + @field(Pollable.Tag, "BufferedOutput") => { + var loader = ptr.as(JSC.Subprocess.BufferedOutput); + + loader.poll_ref.deactivate(loop); + + loader.ready(0); + }, else => unreachable, } } @@ -535,6 +559,7 @@ pub const Poller = struct { const FileSink = JSC.WebCore.FileSink; const Subprocess = JSC.Subprocess; const BufferedInput = Subprocess.BufferedInput; + const BufferedOutput = Subprocess.BufferedOutput; /// epoll only allows one pointer /// We unfortunately need two pointers: one for a function call and one for the context /// We use a tagged pointer union and then call the function with the context pointer @@ -543,6 +568,7 @@ pub const Poller = struct { FileSink, Subprocess, BufferedInput, + BufferedOutput, }); const Kevent = std.os.Kevent; const kevent = std.c.kevent; 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(); |