lock

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

type Lock interface {
	// Lock try  get a lock for given key
	Lock(key string) (observer LockResult, acquired bool)
	// Release remove lock for given key
	Release(key string)
	// NotifyAndRelease remove lock for given key and notify all clients waiting for result
	NotifyAndRelease(key string, res *response.Response)
}

Lock is responding for collapsing request for same object

type LockResult

type LockResult struct {
	ResponseChan chan *response.Response // channel on which you get response
	Cancel       chan bool               // channel for notify about cancel of waiting
}

LockResult contain struct

type MemoryLock

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

MemoryLock is in memory lock for single mort instance

func NewMemoryLock

func NewMemoryLock() *MemoryLock

NewMemoryLock create a new empty instance of MemoryLock

func (*MemoryLock) Lock

func (m *MemoryLock) Lock(key string) (LockResult, bool)

Lock create unique entry in memory map

func (*MemoryLock) NotifyAndRelease

func (m *MemoryLock) NotifyAndRelease(key string, originalResponse *response.Response)

NotifyAndRelease tries notify all waiting goroutines about response

func (*MemoryLock) Release

func (m *MemoryLock) Release(key string)

Release remove entry from memory map

type NopLock

type NopLock struct {
}

NopLock will never collapse any request

func NewNopLock

func NewNopLock() *NopLock

NewNopLock create lock that do nothing

func (*NopLock) Lock

func (l *NopLock) Lock(_ string) (LockResult, bool)

Lock always return that lock was acquired

func (*NopLock) NotifyAndRelease

func (l *NopLock) NotifyAndRelease(_ string, _ *response.Response)

NotifyAndRelease do nothing

func (*NopLock) Release

func (l *NopLock) Release(_ string)

Release do nothing

Jump to

Keyboard shortcuts

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