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 ¶
- type Client
- func (c *Client) DoOnce(ctx context.Context, key string, f func()) (err error)
- func (c *Client) DoOnceEnd(ctx context.Context, key string) error
- func (c *Client) DoOnceStart(ctx context.Context, key string) (bool, error)
- func (c *Client) Get(ctx context.Context, key string) (string, error)
- func (c *Client) Lock(ctx context.Context, key string) (string, error)
- func (c *Client) Locker(key string) sync.Locker
- func (c *Client) Unlock(ctx context.Context, key, token string) error
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 (*Client) DoOnce ¶
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) DoOnceStart ¶
DoOnceStart begins a do-once section. It reports if the operation to perform exactly once should proceed.
func (*Client) Lock ¶
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 ¶
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.