package worker import ( "fmt" "sync/atomic" ) type Scheduler struct { pool chan any count atomic.Int64 } func NewScheduler(count uint) *Scheduler { return &Scheduler{ pool: make(chan any, count), } } func (self *Scheduler) Take() { self.pool <- nil self.count.Add(1) fmt.Printf("<- %d\n", self.count.Load()) } func (self *Scheduler) Return() { <-self.pool self.count.Add(-1) fmt.Printf("-> %d\n", self.count.Load()) }