New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idea: barrier #117

Open
kamilsk opened this Issue Nov 23, 2017 · 1 comment

Comments

@kamilsk
Copy link
Owner

kamilsk commented Nov 23, 2017

Resizeable semaphore potentially can have over-engineered implementation. The main objective to create resizeable semaphore is to make graceful degradation, so, the simplest way is to create barrier:

s := semaphore.New(1000)
w := watcher.New()
w.On(event.Overloading, func () { s.SetBarrier(700) }) // capacity of semaphore will be equal to 300
go w.Watch()

@kamilsk kamilsk added this to the semaphore 5.0 milestone Nov 23, 2017

@kamilsk kamilsk self-assigned this Nov 23, 2017

@kamilsk

This comment has been minimized.

Copy link
Owner Author

kamilsk commented Nov 24, 2017

possible implementation:

type sem struct {
  s chan struct{}
  b chan struct{}
}

func (s *sem) SetBarrier(b int) {
  // do validation

  // lock is needed?

  for len(s.b) == b {
    s.b <- s.s
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment