noop

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package noop is the distributedlock implementation for a deployment with nothing to coordinate with: Acquire always succeeds immediately, WithLock always runs fn, and TryWithLock always reports the lock as taken.

This provider is correct at one replica

It provides no mutual exclusion of any kind, which makes it correct at exactly one process and silently wrong above that. Two replicas holding "the same" lock both proceed into the critical section, and nothing here detects the second one or reports the contention it did not arbitrate. It fails as a double-processed job or a lost update rather than as an error. That is a constraint on the deployment, not a tuning knob — a service that scales out wants the redis or postgres provider instead, where the lock lives somewhere both replicas can see it.

Its lock handles are real enough to pass around: Key and TTL echo back what Acquire was given, and Refresh updates the TTL it will echo. Nothing is stored anywhere and no expiry is ever enforced, so a handle that outlives its TTL is still held.

distributedlock/config builds either type for the "noop" provider name.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

type Locker struct{}

Locker is a no-op distributedlock.Locker. Acquire always succeeds, Release and Refresh are no-ops, Ping returns nil. Use this when distributed locking is not needed in a given deployment (single replica, dev environments, etc.).

func NewLocker

func NewLocker() *Locker

NewLocker returns a no-op Locker.

func (*Locker) Acquire

func (*Locker) Acquire(_ context.Context, key string, ttl time.Duration) (distributedlock.Lock, error)

Acquire always returns a trivial lock handle.

func (*Locker) Close

func (*Locker) Close() error

Close is a no-op.

func (*Locker) Ping

func (*Locker) Ping(_ context.Context) error

Ping is a no-op that always succeeds.

type ScopedLocker

type ScopedLocker struct{}

ScopedLocker is a no-op distributedlock.ScopedLocker: fn always runs, as if the lock were acquired immediately. Use it where scoped locking is wired but a deployment has nothing to coordinate with (single replica, dev).

func NewScopedLocker

func NewScopedLocker() *ScopedLocker

NewScopedLocker returns a no-op ScopedLocker.

func (*ScopedLocker) TryWithLock

func (*ScopedLocker) TryWithLock(ctx context.Context, _ string, fn func(ctx context.Context) error) (bool, error)

TryWithLock runs fn immediately, always reporting the lock as acquired.

func (*ScopedLocker) WithLock

func (*ScopedLocker) WithLock(ctx context.Context, _ string, fn func(ctx context.Context) error) error

WithLock runs fn immediately.

Jump to

Keyboard shortcuts

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