singlefile

package module
v0.0.0-...-0d87fc8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2015 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package singlefile implements a host wide locking mechanism.

Singlefile can be used to ensure that two scheduled processes on a host do not run at the same time.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lock

func Lock(key string) (unlock func() error, err error)

Lock takes a host wide lock on the specified key. Lock is guarenteed to release the lock when the process exits, even if that is uncontrolled (runtime panic, OOM killer, etc). Lock returns an unlock function, and an error indicating the success or failure of the lock operation. The unlock function may be used to release the lock before the end of the program execution. key must not be an empty string and implementations may require that they key is of sufficient length to ensure uniqueness.

Example
package main

import (
	"log"

	"github.com/pkg/singlefile"
)

func main() {
	const key = "xyzzy"
	unlock, err := singlefile.Lock(key)
	if err != nil {
		log.Fatalf("could not aquire singlefile lock: %v", err)
	}
	defer unlock()
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL