lock

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

This package provides a blocking Lock(...) / Unlock() function pair. The basic usage will look something like:

ctx := context.Background()
client, _ := spanner.NewClient(ctx, "your/database")
defer db.Close()

slock := lock.NewSpindleLock(&lock.SpindleLockOptions{
    Client:   client,
    Table:    "testlease",
    Name:     "dlock",
    Duration: 1000,
})

start := time.Now()
slock.Lock(ctx)
log.Printf("lock acquired after %v, do protected work...", time.Since(start))
time.Sleep(time.Second * 5)
slock.Unlock()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout = fmt.Errorf("timeout")
)

Functions

This section is empty.

Types

type SpindleLock

type SpindleLock struct {
	// contains filtered or unexported fields
}

func NewSpindleLock

func NewSpindleLock(opts *SpindleLockOptions) *SpindleLock

func (*SpindleLock) Lock

func (l *SpindleLock) Lock(ctx context.Context) error

func (*SpindleLock) Unlock

func (l *SpindleLock) Unlock() error

type SpindleLockOptions

type SpindleLockOptions struct {
	Client   *spanner.Client // Spanner client
	Table    string          // Spanner table name
	Name     string          // lock name
	Id       string          // optional, generated if empty
	Duration int64           // optional, will use spindle's default
	Logger   *log.Logger     // pass to spindle
}

Jump to

Keyboard shortcuts

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