syncx

package
v1.10.27 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 10 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitReturn = errors.New("discarding limited token, resource pool is full, someone returned multiple times")

ErrLimitReturn indicates that the more than borrowed elements were returned.

View Source
var ErrTimeout = errors.New("borrow timeout")
View Source
var ErrUseOfCleaned = errors.New("using a cleaned resource")

Functions

func Once

func Once(fn func()) func()

Types

type AtomicBool

type AtomicBool uint32

func ForAtomicBool

func ForAtomicBool(val bool) *AtomicBool

func NewAtomicBool

func NewAtomicBool() *AtomicBool

func (*AtomicBool) CompareAndSwap

func (b *AtomicBool) CompareAndSwap(old, val bool) bool

func (*AtomicBool) Set

func (b *AtomicBool) Set(v bool)

func (*AtomicBool) True

func (b *AtomicBool) True() bool

type AtomicDuration

type AtomicDuration int64

func ForAtomicDuration

func ForAtomicDuration(val time.Duration) *AtomicDuration

func NewAtomicDuration

func NewAtomicDuration() *AtomicDuration

func (*AtomicDuration) CompareAndSwap

func (d *AtomicDuration) CompareAndSwap(old, val time.Duration) bool

func (*AtomicDuration) Load

func (d *AtomicDuration) Load() time.Duration

func (*AtomicDuration) Set

func (d *AtomicDuration) Set(val time.Duration)

type AtomicFloat64

type AtomicFloat64 uint64

func ForAtomicFloat64

func ForAtomicFloat64(val float64) *AtomicFloat64

func NewAtomicFloat64

func NewAtomicFloat64() *AtomicFloat64

func (*AtomicFloat64) Add

func (f *AtomicFloat64) Add(val float64) float64

func (*AtomicFloat64) CompareAndSwap

func (f *AtomicFloat64) CompareAndSwap(old, val float64) bool

func (*AtomicFloat64) Load

func (f *AtomicFloat64) Load() float64

func (*AtomicFloat64) Set

func (f *AtomicFloat64) Set(val float64)

type Barrier

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

func (*Barrier) Guard

func (b *Barrier) Guard(fn func())

type Cond

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

func NewCond

func NewCond() *Cond

func (*Cond) Signal

func (cond *Cond) Signal()

Signal wakes one goroutine waiting on c, if there is any.

func (*Cond) Wait

func (cond *Cond) Wait()

Wait for signal

func (*Cond) WaitWithTimeout

func (cond *Cond) WaitWithTimeout(timeout time.Duration) (time.Duration, bool)

WaitWithTimeout wait for signal return remain wait time or timed out

type DoneChan

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

func NewDoneChan

func NewDoneChan() *DoneChan

func (*DoneChan) Close

func (dc *DoneChan) Close()

func (*DoneChan) Done

func (dc *DoneChan) Done() chan lang.PlaceholderType

type ImmutableResource

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

func NewImmutableResource

func NewImmutableResource(fn func() (interface{}, error), opts ...ImmutableResourceOption) *ImmutableResource

func (*ImmutableResource) Get

func (ir *ImmutableResource) Get() (interface{}, error)

type ImmutableResourceOption

type ImmutableResourceOption func(resource *ImmutableResource)

func WithRefreshIntervalOnFailure

func WithRefreshIntervalOnFailure(interval time.Duration) ImmutableResourceOption

Set interval to 0 to enforce refresh every time if not succeeded. default is time.Second.

type Limit

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

Limit controls the concurrent requests.

func NewLimit

func NewLimit(n int) Limit

NewLimit creates a Limit that can borrow n elements from it concurrently.

func (Limit) Borrow

func (l Limit) Borrow()

Borrow borrows an element from Limit in blocking mode.

func (Limit) Return

func (l Limit) Return() error

Return returns the borrowed resource, returns error only if returned more than borrowed.

func (Limit) TryBorrow

func (l Limit) TryBorrow() bool

TryBorrow tries to borrow an element from Limit, in non-blocking mode. If success, true returned, false for otherwise.

type LockedCalls

type LockedCalls interface {
	Do(key string, fn func() (interface{}, error)) (interface{}, error)
}

LockedCalls makes sure the calls with the same key to be called sequentially. For example, A called F, before it's done, B called F, then B's call would not blocked, after A's call finished, B's call got executed. The calls with the same key are independent, not sharing the returned values. A ------->calls F with key and executes<------->returns B ------------------>calls F with key<--------->executes<---->returns

func NewLockedCalls

func NewLockedCalls() LockedCalls

type ManagedResource

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

func NewManagedResource

func NewManagedResource(generate func() interface{}, equals func(a, b interface{}) bool) *ManagedResource

func (*ManagedResource) MarkBroken

func (mr *ManagedResource) MarkBroken(resource interface{})

func (*ManagedResource) Take

func (mr *ManagedResource) Take() interface{}

type OnceGuard

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

func (*OnceGuard) Take

func (og *OnceGuard) Take() bool

func (*OnceGuard) Taken

func (og *OnceGuard) Taken() bool

type Pool

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

func NewPool

func NewPool(n int, create func() interface{}, destroy func(interface{}), opts ...PoolOption) *Pool

func (*Pool) Get

func (p *Pool) Get() interface{}

func (*Pool) Put

func (p *Pool) Put(x interface{})

type PoolOption

type PoolOption func(*Pool)

func WithMaxAge

func WithMaxAge(duration time.Duration) PoolOption

type RefResource

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

func NewRefResource

func NewRefResource(clean func()) *RefResource

func (*RefResource) Clean

func (r *RefResource) Clean()

func (*RefResource) Use

func (r *RefResource) Use() error

type ResourceManager

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

func NewResourceManager

func NewResourceManager() *ResourceManager

func (*ResourceManager) Close

func (manager *ResourceManager) Close() error

func (*ResourceManager) GetResource

func (manager *ResourceManager) GetResource(key string, create func() (io.Closer, error)) (io.Closer, error)

type SharedCalls

type SharedCalls interface {
	Do(key string, fn func() (interface{}, error)) (interface{}, error)
	DoEx(key string, fn func() (interface{}, error)) (interface{}, bool, error)
}

SharedCalls lets the concurrent calls with the same key to share the call result. For example, A called F, before it's done, B called F. Then B would not execute F, and shared the result returned by F which called by A. The calls with the same key are dependent, concurrent calls share the returned values. A ------->calls F with key<------------------->returns val B --------------------->calls F with key------>returns val

func NewSharedCalls

func NewSharedCalls() SharedCalls

type SpinLock

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

func (*SpinLock) Lock

func (sl *SpinLock) Lock()

func (*SpinLock) TryLock

func (sl *SpinLock) TryLock() bool

func (*SpinLock) Unlock

func (sl *SpinLock) Unlock()

type TimeoutLimit

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

func NewTimeoutLimit

func NewTimeoutLimit(n int) TimeoutLimit

func (TimeoutLimit) Borrow

func (l TimeoutLimit) Borrow(timeout time.Duration) error

func (TimeoutLimit) Return

func (l TimeoutLimit) Return() error

func (TimeoutLimit) TryBorrow

func (l TimeoutLimit) TryBorrow() bool

Jump to

Keyboard shortcuts

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