1package worker
2
3import (
4 "fmt"
5 "sync/atomic"
6)
7
8type Scheduler struct {
9 pool chan any
10 count atomic.Int64
11}
12
13func NewScheduler(count uint) *Scheduler {
14 return &Scheduler{
15 pool: make(chan any, count),
16 }
17}
18
19func (self *Scheduler) Take() {
20 self.pool <- nil
21 self.count.Add(1)
22 fmt.Printf("<- %d\n", self.count.Load())
23}
24
25func (self *Scheduler) Return() {
26 <-self.pool
27 self.count.Add(-1)
28 fmt.Printf("-> %d\n", self.count.Load())
29}