conc icon indicating copy to clipboard operation
conc copied to clipboard

fix: prevent sequential execution in Stream without goroutine limit

Open Yanhu007 opened this issue 7 months ago • 0 comments

Fixes #153

Problem

When no WithMaxGoroutines is called, pool.MaxGoroutines() returns 0 (the cap of a nil channel). The stream queue is then:

s.queue = make(chan callbackCh, 0+1) // buffer of 1

Since Go() must send to the queue before spawning the pool goroutine, only 1 task can be inflight at a time — effectively serializing execution despite an unlimited pool.

Fix

When MaxGoroutines() returns 0 (unlimited), use runtime.GOMAXPROCS(0) as a reasonable default queue buffer. This lets multiple tasks run concurrently while matching the pool's unlimited behavior.

Testing

All existing tests pass, including the stream-specific tests.

Yanhu007 avatar Apr 14 '26 03:04 Yanhu007