lock

package
v3.73.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package lock provides a client for the Agent API locking service. This is intended to be used both internally by the agent itself, as well as by authors of binary hooks or other programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements a client library for the Agent API locking service.

func NewClient

func NewClient(ctx context.Context, socketsDir string) (*Client, error)

NewClient creates a new machine-scope lock service client.

func (*Client) DoOnce

func (c *Client) DoOnce(ctx context.Context, key string, f func()) (err error)

DoOnce is similar to sync.Once. In the absence of an error, it does one of two things:

  • Calls f, and returns when done.
  • Waits until another invocation with this key has completed, and then returns.

Like sync.Once, if f panics, DoOnce considers it to have returned.

func (*Client) DoOnceEnd

func (c *Client) DoOnceEnd(ctx context.Context, key string) error

DoOnceEnd marks a do-once section as completed.

func (*Client) DoOnceStart

func (c *Client) DoOnceStart(ctx context.Context, key string) (bool, error)

DoOnceStart begins a do-once section. It reports if the operation to perform exactly once should proceed.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) (string, error)

Get retrieves the current state of a lock.

func (*Client) Lock

func (c *Client) Lock(ctx context.Context, key string) (string, error)

Lock blocks until the lock for the given key is acquired. It returns a token or an error. The token must be passed to Unlock in order to unlock the lock later on.

func (*Client) Locker

func (c *Client) Locker(key string) sync.Locker

Locker returns a sync.Mutex-like object that uses the client to perform locking. Any errors encountered by the client while locking or unlocking (for example, the agent running the API stops running) will cause a panic (because sync.Locker has no other way to report an error). For greater flexibility, use Client's Lock and Unlock methods directly.

func (*Client) Unlock

func (c *Client) Unlock(ctx context.Context, key, token string) error

Unlock unlocks the lock for the given key. To prevent different processes accidentally unlocking the same lock, token must match the current lock value.

Jump to

Keyboard shortcuts

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