Skip to content

Commit adc504c

Browse files
feat: add task API for bidirectional background worker communication
1 parent 8478c84 commit adc504c

28 files changed

+1583
-10
lines changed

background_worker.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ func (registry *backgroundWorkerRegistry) reserve(name string) (*backgroundWorke
163163

164164
bgw := &backgroundWorkerState{
165165
ready: make(chan struct{}),
166+
tasks: make(chan *taskRequest, 1), // buffer=1: backpressure with signaling
167+
dead: make(chan struct{}),
166168
}
167169
registry.workers[name] = bgw
168170

@@ -176,6 +178,9 @@ func (registry *backgroundWorkerRegistry) remove(name string, bgw *backgroundWor
176178
if registry.workers[name] == bgw {
177179
delete(registry.workers, name)
178180
}
181+
182+
// Signal waiting senders that this worker is gone
183+
bgw.deadOnce.Do(func() { close(bgw.dead) })
179184
}
180185

181186
func startBackgroundWorker(thread *phpThread, bgWorkerName string) error {
@@ -225,6 +230,7 @@ func startBackgroundWorkerWithRegistry(registry *backgroundWorkerRegistry, bgWor
225230
worker.isBackgroundWorker = true
226231
worker.backgroundWorker = bgw
227232
worker.backgroundRegistry = registry
233+
bgw.fds = &worker.backgroundFds
228234

229235
for i := 0; i < numThreads; i++ {
230236
bgWorkerThread := getInactivePHPThread()

0 commit comments

Comments
 (0)