Skip to content

Commit

Permalink
add a new HasLock2 fn with leader id
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Nov 22, 2024
1 parent 1878d13 commit f0bb696
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spindle.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,24 @@ func (l *Lock) HasLock() (bool, uint64) {
return false, token
}

// HasLock2 is HasLock but return the leader id as well.
func (l *Lock) HasLock2() (bool, string, uint64) {
if l.active.Load() == 0 {
return false, "", 0
}

token, w, err := l.getCurrentToken()
if err != nil {
return false, "", 0
}

if token == l.token() {
return true, w, token
}

return false, w, token
}

// Leader returns the current leader id.
func (l *Lock) Leader() (string, error) {
if l.active.Load() == 0 {
Expand Down

0 comments on commit f0bb696

Please sign in to comment.