本文整理匯總了Golang中github.com/coreos/locksmith/lock.Lock類的典型用法代碼示例。如果您正苦於以下問題:Golang Lock類的具體用法?Golang Lock怎麽用?Golang Lock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Lock類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: unlockIfHeld
// unlockIfHeld will unlock a lock, if it is held by this machine, or return an error.
func unlockIfHeld(lck *lock.Lock) error {
err := lck.Unlock()
if err == lock.ErrNotExist {
return nil
} else if err == nil {
fmt.Println("Unlocked existing lock for this machine")
return nil
}
return err
}
示例2: lockAndReboot
// lockAndReboot attempts to acquire the lock and reboot the machine in an
// infinite loop. Returns if the reboot failed.
func (r rebooter) lockAndReboot(lck *lock.Lock) {
interval := initialInterval
for {
err := lck.Lock()
if err != nil && err != lock.ErrExist {
interval = expBackoff(interval)
fmt.Printf("Retrying in %v. Error locking: %v\n", interval, err)
time.Sleep(interval)
continue
}
rebootAndSleep(r.lgn)
return
}
}