diff options
| author | 2022-10-05 18:00:36 -0700 | |
|---|---|---|
| committer | 2022-10-05 18:07:41 -0700 | |
| commit | 707b454bf480dc595d319a387b36f5f1e069b716 (patch) | |
| tree | ad5d73680e0b0ca46fb6a5236308ef92ad607f3f /src | |
| parent | ca4c99b1bfa6488b36da11456e497f2e4bcd282d (diff) | |
| download | bun-707b454bf480dc595d319a387b36f5f1e069b716.tar.gz bun-707b454bf480dc595d319a387b36f5f1e069b716.tar.zst bun-707b454bf480dc595d319a387b36f5f1e069b716.zip | |
Support buffered input in Bun.spawn
Diffstat (limited to 'src')
| -rw-r--r-- | src/bun.js/event_loop.zig | 22 | 
1 files changed, 15 insertions, 7 deletions
| diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 76206de54..0ce2394c7 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -324,6 +324,13 @@ pub const EventLoop = struct {          return this.tasks.count - start_count;      } +    pub fn autoTick(this: *EventLoop) void { +        if (this.virtual_machine.uws_event_loop.?.num_polls > 0 or this.virtual_machine.uws_event_loop.?.active > 0) { +            this.virtual_machine.uws_event_loop.?.tick(); +            this.afterUSocketsTick(); +        } +    } +      // TODO: fix this technical debt      pub fn tick(this: *EventLoop) void {          var ctx = this.virtual_machine; @@ -380,9 +387,7 @@ pub const EventLoop = struct {                      this.tick();                      if (promise.status(this.global.vm()) == .Pending) { -                        if (this.virtual_machine.uws_event_loop.?.active > 0 or this.virtual_machine.uws_event_loop.?.num_polls > 0) { -                            this.virtual_machine.uws_event_loop.?.tick(); -                        } +                        this.autoTick();                      }                  }              }, @@ -420,7 +425,6 @@ pub const EventLoop = struct {      }      pub fn afterUSocketsTick(this: *EventLoop) void { -        this.defer_count.store(0, .Monotonic);          const processes = this.pending_processes_to_exit.keys();          if (processes.len > 0) {              for (processes) |process| { @@ -428,8 +432,6 @@ pub const EventLoop = struct {              }              this.pending_processes_to_exit.clearRetainingCapacity();          } - -        this.tick();      }      pub fn enqueueTaskConcurrent(this: *EventLoop, task: *ConcurrentTask) void { @@ -438,7 +440,6 @@ pub const EventLoop = struct {          this.concurrent_tasks.push(task);          if (this.virtual_machine.uws_event_loop) |loop| { -            _ = this.defer_count.fetchAdd(1, .Monotonic);              loop.wakeup();          }      } @@ -471,6 +472,13 @@ pub const Poller = struct {                  // so we have to dedupe it                  _ = loader.globalThis.bunVM().eventLoop().pending_processes_to_exit.getOrPut(loader) catch unreachable;              }, +            @field(Pollable.Tag, "BufferedInput") => { +                var loader = ptr.as(JSC.Subprocess.BufferedInput); + +                loader.poll_ref.deactivate(loop); + +                loader.onReady(@bitCast(i64, kqueue_event.data)); +            },              @field(Pollable.Tag, "FileSink") => {                  var loader = ptr.as(JSC.WebCore.FileSink);                  loader.poll_ref.deactivate(loop); | 
