Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrBusy = errors.New("Locked by other process") // If you get this, retry after a short sleep might help ErrNeedAbsPath = errors.New("Lockfiles must be given as absolute path names") ErrInvalidPid = errors.New("Lockfile contains invalid pid for system") ErrDeadOwner = errors.New("Lockfile contains pid of process not existent on this system anymore") )
Functions ¶
This section is empty.
Types ¶
type Lockfile ¶
type Lockfile struct {
Path string
}
Example ¶
package main import ( "fmt" "github.com/dropbox/changes-client/common/lockfile" ) func main() { lock, err := lockfile.New("/tmp/lock.me.now.lck") if err != nil { fmt.Printf("Cannot init lock. reason: %s\n", err) panic(err) } err = lock.TryLock() // Error handling is essential, as we only try to get the lock. if err != nil { fmt.Printf("Cannot lock \"%v\", reason: %s\n", lock, err) panic(err) } defer lock.Unlock() fmt.Println("Do stuff under lock") }
Output: Do stuff under lock
Click to show internal directories.
Click to hide internal directories.