sync

package
v0.0.0-...-99984a4 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: Apache-2.0 Imports: 4 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines.

func NewMap

func NewMap() *Map

NewMap creates map.

func (*Map) Delete

func (m *Map) Delete(key interface{})

Delete deletes the value for a key.

func (*Map) DeleteWithFunc

func (m *Map) DeleteWithFunc(key interface{}, onDeleteFunc func(value interface{}))

func (*Map) Length

func (m *Map) Length() int

Length returns number of stored values.

func (*Map) Load

func (m *Map) Load(key interface{}) (value interface{}, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*Map) LoadOrStore

func (m *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*Map) LoadOrStoreWithFunc

func (m *Map) LoadOrStoreWithFunc(key interface{}, onLoadFunc func(value interface{}) interface{}, createFunc func() interface{}) (actual interface{}, loaded bool)

func (*Map) LoadWithFunc

func (m *Map) LoadWithFunc(key interface{}, onLoadFunc func(value interface{}) interface{}) (value interface{}, ok bool)

func (*Map) PullOut

func (m *Map) PullOut(key interface{}) (value interface{}, ok bool)

PullOut loads and deletes the value for a key.

func (*Map) PullOutAll

func (m *Map) PullOutAll() (data map[interface{}]interface{})

PullOutAll extracts internal map data and replace it with empty map.

func (*Map) PullOutWithFunc

func (m *Map) PullOutWithFunc(key interface{}, onLoadFunc func(value interface{}) interface{}) (value interface{}, ok bool)

func (*Map) Range

func (m *Map) Range(f func(key, value interface{}) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (*Map) Replace

func (m *Map) Replace(key, value interface{}) (oldValue interface{}, oldLoaded bool)

Replace replaces the existing value with a new value and returns old value for the key.

func (*Map) ReplaceWithFunc

func (m *Map) ReplaceWithFunc(key interface{}, onReplaceFunc func(oldValue interface{}, oldLoaded bool) (newValue interface{}, delete bool)) (oldValue interface{}, oldLoaded bool)

func (*Map) Store

func (m *Map) Store(key, value interface{})

Store sets the value for a key.

func (*Map) StoreWithFunc

func (m *Map) StoreWithFunc(key interface{}, createFunc func() interface{})

type Once

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

Once performs exactly one action. See sync.Once for more details.

func (*Once) Done

func (o *Once) Done() bool

Done returns true after Try executes succesfully.

func (*Once) Try

func (o *Once) Try(f func() bool)

Try executes the function f exactly once for this instance of Once. If the function f returns false, it enables further execution attempts.

type Pool

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

Pool is a synchronized key-value store with customizable factory for missing items.

func NewPool

func NewPool() *Pool

NewPool creates a pool.

func (*Pool) Delete

func (p *Pool) Delete(key string) (_ interface{}, ok bool)

Delete pops an item from the pool or false.

func (*Pool) Get

func (p *Pool) Get(key string) (_ interface{}, ok bool)

Get returns an item from the pool or false.

func (*Pool) GetOrCreate

func (p *Pool) GetOrCreate(ctx context.Context, key string) (interface{}, error)

GetOrCreate returns an item and calls the factory on a mis. Warning: The factory function is called under the lock, therefore it must not call any Pool's methods to avoid deadlocks.

func (*Pool) Put

func (p *Pool) Put(key string, item interface{})

Put adds an item to the pool.

func (*Pool) SetFactory

func (p *Pool) SetFactory(f PoolFunc)

SetFactory sets the pool factory for GetOrCreate.

type PoolFunc

type PoolFunc func(ctx context.Context, key string) (interface{}, error)

PoolFunc is triggered on a miss by GetOrCreate, so that it may add the missing item to the pool.

type RefCounter

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

func NewRefCounter

func NewRefCounter(data interface{}, releaseDataFunc ReleaseDataFunc) *RefCounter

NewRefCounter creates RefCounter

func (*RefCounter) Acquire

func (r *RefCounter) Acquire()

Acquire increments counter

func (*RefCounter) Count

func (r *RefCounter) Count() int64

Count returns current counter value.

func (*RefCounter) Data

func (r *RefCounter) Data() interface{}

Data returns data

func (*RefCounter) Release

func (r *RefCounter) Release(ctx context.Context) error

Release decrements counter, when counter reach 0, releaseDataFunc will be called

type ReleaseDataFunc

type ReleaseDataFunc = func(ctx context.Context, data interface{}) error

Directories

Path Synopsis
task

Jump to

Keyboard shortcuts

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