dlock

package module
v0.0.0-...-4a7144f Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: Apache-2.0 Imports: 5 Imported by: 1

README

mattermost-dlock

A distributed lock to be used within Mattermost Plugins.

Please read this topic to see real world use cases of distributed locks while building Mattermost Plugins.

Documentation

Overview

Package dlock is a distributed lock to enable advanced synchronization for Mattermost Plugins.

if you're new to distributed locks and Mattermost Plugins please read sample use case scenarios at: https://community.mattermost.com/core/pl/bb376sjsdbym8kj7nz7zrcos7r

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCouldntObtainImmediately returned when a lock couldn't be obtained immediately after
	// calling Lock().
	ErrCouldntObtainImmediately = errors.New("could not obtain immediately")
)

Functions

This section is empty.

Types

type DLock

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

DLock is a distributed lock.

func New

func New(key string, store Store) *DLock

New creates a new distributed lock for key on given store with options. think,

`dl := New("my-key", store)`

as an equivalent of,

`var m sync.Mutex`

and use it in the same way.

func (*DLock) Lock

func (d *DLock) Lock(ctx context.Context) error

Lock obtains a new lock. ctx provides a context to locking. when ctx is cancelled, Lock() will stop blocking and retries and return with error. use Lock() exactly like sync.Mutex.Lock(), avoid missuses like deadlocks.

func (*DLock) TryLock

func (d *DLock) TryLock() (isLockObtained bool, err error)

TryLock tries to obtain the lock immediately. err is only filled on system failure.

func (*DLock) Unlock

func (d *DLock) Unlock() error

Unlock unlocks Lock(). use Unlock() exactly like sync.Mutex.Unlock().

type Store

type Store interface {
	KVSetWithOptions(key string, newValue interface{}, options model.PluginKVSetOptions) (bool, *model.AppError)
	KVDelete(key string) *model.AppError
}

Store is a data store to keep locks' state.

Directories

Path Synopsis
Package dlocktest is a testing helper for you to unit test your packages that using dlock.
Package dlocktest is a testing helper for you to unit test your packages that using dlock.

Jump to

Keyboard shortcuts

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