namedlocker

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 2 Imported by: 4

README

namedlocker

Package namedlocker implements in-memory named locks. See https://oya.to/namedlocker for docs.

Install

go get oya.to/namedlocker

Usage

package test


func Example() {
    sto := Store{}
    sto.Lock("my-key")
    defer sto.Unlock("my-key")

    // do some work...
}

Documentation

Overview

Package namedlocker implements in-memory named locks.

Example
sto := Store{}
sto.Lock("my-key")
defer sto.Unlock("my-key")

// do some work...
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnlockOfUnlockedKey is the error reported when unlocking an unlocked key.
	ErrUnlockOfUnlockedKey = errors.New("unlock of unlocked key")
)

Functions

This section is empty.

Types

type Store

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

Store is an in-memory store of named locks.

The zero-value is usable as-is.

func (*Store) Lock

func (s *Store) Lock(key string)

Lock acquires a lock on key. If key is locked, it blocks until it can be acquired.

func (*Store) TryUnlock

func (s *Store) TryUnlock(key string) error

TryUnlock releases the lock on key.

If key is not locked, ErrUnlockOfUnlockedKey is returned.

func (*Store) Unlock

func (s *Store) Unlock(key string)

Unlock is a wrapper around TryUnlock that panics if it returns an error.

Jump to

Keyboard shortcuts

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