xsync

package module
v0.1.1 Latest Latest
Warning

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

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

README

xsync

Install

go get -u github.com/chenquan/xsync

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchError

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

A BatchError is an error that can hold multiple errors.

func (*BatchError) Add

func (be *BatchError) Add(err error)

Add adds err to be.

func (*BatchError) Err

func (be *BatchError) Err() error

Err returns an error that represents all errors.

func (*BatchError) NotNil

func (be *BatchError) NotNil() bool

NotNil checks if any error inside.

type Map

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

Map from standard library

func (*Map) ComputeIfAbsent

func (m *Map) ComputeIfAbsent(key interface{}, computeFunc func(key interface{}) interface{}) (actual interface{}, loaded bool)

ComputeIfAbsent if the value corresponding to the key does not exist, use the recalculated value obtained by remappingFunction and save it as the value of the key, otherwise return the value.

func (*Map) ComputeIfPresent

func (m *Map) ComputeIfPresent(key interface{}, computeFunc func(key, value interface{}) interface{}) (actual interface{}, exist bool)

ComputeIfPresent if the value corresponding to the key does not exist, the null is returned, and if it exists, the value recalculated by remappingFunction is returned.

func (*Map) Delete

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

Delete deletes the value for a key.

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) LoadAndDelete

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

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

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) 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.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*Map) Store

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

Store sets the value for a key.

type Queue

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

func NewQueue

func NewQueue(opts ...QueueOption) *Queue

func (*Queue) Cap

func (q *Queue) Cap(cap int)

func (*Queue) Close

func (q *Queue) Close() error

func (*Queue) Read

func (q *Queue) Read() interface{}

func (*Queue) Remove

func (q *Queue) Remove(v interface{}) (ok bool)

func (*Queue) Write

func (q *Queue) Write(v interface{})

type QueueMode

type QueueMode byte
const (
	MultiRead      QueueMode = 1
	MultiWrite     QueueMode = 2
	MultiReadWrite           = MultiRead | MultiWrite
)

type QueueOption

type QueueOption func(opt *QueueOptions)

func WithQueueCap

func WithQueueCap(cap int) QueueOption

func WithQueueMode

func WithQueueMode(mode QueueMode) QueueOption

type QueueOptions

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

type ResourceManager

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

func NewResourceManager

func NewResourceManager() *ResourceManager

NewResourceManager returns a ResourceManager.

func (*ResourceManager) Close

func (m *ResourceManager) Close() error

Close the manager. Don't use the ResourceManager after Close() called.

func (*ResourceManager) Get

func (m *ResourceManager) Get(key string, create func() (io.Closer, error)) (io.Closer, error)

Get returns the resource associated with given key.

func (*ResourceManager) Remove

func (m *ResourceManager) Remove(key string) (exist bool)

Remove the resource associated with given key and return it if existed.

type Spinlock

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

Spinlock represents a spin lock.

func (*Spinlock) Lock

func (lock *Spinlock) Lock()

Lock locks the Spinlock.

func (*Spinlock) TryLock

func (lock *Spinlock) TryLock() bool

TryLock tries to lock the Spinlock.

func (*Spinlock) Unlock

func (lock *Spinlock) Unlock()

Unlock unlocks the Spinlock.

Jump to

Keyboard shortcuts

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