Skip to content

Commit

Permalink
add Semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
markus621 committed Aug 2, 2024
1 parent 383548f commit e28926c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions control/semaphore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package control

type (
Semaphore interface {
Acquire()
Release()
}
_semaphore struct {
c chan struct{}
}
)

func NewSemaphore(count uint64) Semaphore {
return &_semaphore{
c: make(chan struct{}, count),
}
}

func (s *_semaphore) Acquire() {
s.c <- struct{}{}
}

func (s *_semaphore) Release() {
<-s.c
}

0 comments on commit e28926c

Please sign in to comment.