Skip to content

Commit beec9b4

Browse files
feat: add task API for bidirectional background worker communication
1 parent 824cd51 commit beec9b4

27 files changed

+1558
-10
lines changed

background_worker.go

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

173173
bgw := &backgroundWorkerState{
174174
ready: make(chan struct{}),
175+
tasks: make(chan *taskRequest, 1), // buffer=1: backpressure with signaling
176+
dead: make(chan struct{}),
175177
}
176178
registry.workers[name] = bgw
177179

@@ -185,6 +187,9 @@ func (registry *backgroundWorkerRegistry) remove(name string, bgw *backgroundWor
185187
if registry.workers[name] == bgw {
186188
delete(registry.workers, name)
187189
}
190+
191+
// Signal waiting senders that this worker is gone
192+
bgw.deadOnce.Do(func() { close(bgw.dead) })
188193
}
189194

190195
func startBackgroundWorker(thread *phpThread, bgWorkerName string) error {
@@ -234,6 +239,7 @@ func startBackgroundWorkerWithRegistry(registry *backgroundWorkerRegistry, bgWor
234239
worker.isBackgroundWorker = true
235240
worker.backgroundWorker = bgw
236241
worker.backgroundRegistry = registry
242+
bgw.fds = &worker.backgroundFds
237243

238244
for i := 0; i < numThreads; i++ {
239245
bgWorkerThread := getInactivePHPThread()

0 commit comments

Comments
 (0)