locks

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Modified version of https://github.com/HeavyHorst/certmagic-nats/blob/b27fd6c010166e396b6f9e1c651ba7b02ce6c01f/nats.go#L114 which is licensed under [MIT License](https://github.com/HeavyHorst/certmagic-nats/blob/b27fd6c010166e396b6f9e1c651ba7b02ce6c01f/LICENSE)

Index

Constants

View Source
const (
	LockTimeout = 600 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Locks

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

func New

func New(logger *zap.Logger, kv jetstream.KeyValue, bucket string, maxLockAge time.Duration) (*Locks, error)

func (*Locks) IsLocked

func (l *Locks) IsLocked(ctx context.Context, key string) (bool, error)

func (*Locks) Lock

func (l *Locks) Lock(ctx context.Context, key string) error

Lock acquires the lock for key, blocking until the lock can be obtained or an error is returned. Note that, even after acquiring a lock, an idempotent operation may have already been performed by another process that acquired the lock before - so always check to make sure idempotent operations still need to be performed after acquiring the lock.

The actual implementation of obtaining of a lock must be an atomic operation so that multiple Lock calls at the same time always results in only one caller receiving the lock at any given time.

To prevent deadlocks, all implementations (where this concern is relevant) should put a reasonable expiration on the lock in case Unlock is unable to be called due to some sort of network failure or system crash.

func (*Locks) Unlock

func (l *Locks) Unlock(ctx context.Context, key string) error

Unlock releases the lock for key. This method must ONLY be called after a successful call to Lock, and only after the critical section is finished, even if it errored or timed out. Unlock cleans up any resources allocated during Lock.

Jump to

Keyboard shortcuts

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