Skip to content

Commit

Permalink
Remove the store, Get, SetMax function in lock/lock.go
Browse files Browse the repository at this point in the history
  • Loading branch information
aniruddha2000 committed Oct 20, 2021
1 parent 3a5aae3 commit c003348
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions lock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,6 @@ func New(id string, client LockClient) (lock *Lock) {
return &Lock{id, client}
}

func (l *Lock) store(f func(*Semaphore) error) (err error) {
sem, err := l.client.Get()
if err != nil {
return err
}

if err := f(sem); err != nil {
return err
}

err = l.client.Set(sem)
if err != nil {
return err
}

return nil
}

// Get returns the current semaphore value
// if the underlying client returns an error, Get passes it through
func (l *Lock) Get() (sem *Semaphore, err error) {
sem, err = l.client.Get()
if err != nil {
return nil, err
}

return sem, nil
}

// SetMax sets the maximum number of holders the semaphore will allow
// it returns the current semaphore and the previous maximum
// if there is a problem getting or setting the semaphore, this function will
// pass on errors from the underlying client
func (l *Lock) SetMax(max int) (sem *Semaphore, oldMax int, err error) {
var (
semRet *Semaphore
old int
)

return semRet, old, l.store(func(sem *Semaphore) error {
old = sem.Max
semRet = sem
return sem.SetMax(max)
})
}

// Lock adds this lock id as a holder to the semaphore
// it will return an error if there is a problem getting or setting the
// semaphore, or if the maximum number of holders has been reached, or if a lock
Expand Down

0 comments on commit c003348

Please sign in to comment.