aboutsummaryrefslogtreecommitdiff
path: root/pkg/worker/scheduler.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-02-26 19:54:48 +0100
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-18 16:30:36 +0200
commitc8e1328164e9ffbd681c3c0e449f1e6b9856b896 (patch)
treefaee639a4c55c5dc3bfc59a5400026822c40221d /pkg/worker/scheduler.go
downloadlens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.gz
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.bz2
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.zip
feat: Inicial commit
It contains rough template for the server and runners. It contains rough template for the server and runners.
Diffstat (limited to 'pkg/worker/scheduler.go')
-rw-r--r--pkg/worker/scheduler.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/worker/scheduler.go b/pkg/worker/scheduler.go
new file mode 100644
index 0000000..b410b33
--- /dev/null
+++ b/pkg/worker/scheduler.go
@@ -0,0 +1,29 @@
+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())
+}