syncx

package
v0.0.0-...-09c63dc Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Author:ydy Date: Desc:

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("borrow timeout")

ErrTimeout is an error that indicates the borrow timeout.

Functions

func Once

func Once(f func()) func()

Once returns a func that guarantees fn can only called once.

Types

type AtomicBool

type AtomicBool uint32

An AtomicBool is an atomic implementation for boolean values.

func ForAtomicBool

func ForAtomicBool(val bool) *AtomicBool

ForAtomicBool returns an AtomicBool with given val.

func NewAtomicBool

func NewAtomicBool() *AtomicBool

NewAtomicBool returns an AtomicBool.

func (*AtomicBool) CompareAndSwap

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

CompareAndSwap compares current value with given old, if equals, set to given val.

func (*AtomicBool) Set

func (m *AtomicBool) Set(val bool)

func (*AtomicBool) True

func (m *AtomicBool) True() bool

type AtomicDuration

type AtomicDuration int64

An AtomicDuration is an implementation of atomic duration.

func NewAtomicDuration

func NewAtomicDuration() *AtomicDuration

NewAtomicDuration returns an AtomicDuration.

func (*AtomicDuration) CompareAndSwap

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

CompareAndSwap compares current value with old, if equals, set the value to val.

func (*AtomicDuration) ForAtomicDuration

func (m *AtomicDuration) ForAtomicDuration(time time.Duration) *AtomicDuration

func (*AtomicDuration) Load

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

func (*AtomicDuration) Set

func (m *AtomicDuration) Set(time time.Duration)

type AtomicFloat64

type AtomicFloat64 uint64

An AtomicFloat64 is an implementation of atomic float64.

func ForAtomicFloat64

func ForAtomicFloat64(val float64) *AtomicFloat64

ForAtomicFloat64 returns an AtomicFloat64 with given val.

func NewAtomicFloat64

func NewAtomicFloat64() *AtomicFloat64

NewAtomicFloat64 returns an AtomicFloat64.

func (*AtomicFloat64) Add

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

Add adds val to current value.

func (*AtomicFloat64) CompareAndSwap

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

CompareAndSwap compares current value with old, if equals, set the value to val.

func (*AtomicFloat64) Load

func (m *AtomicFloat64) Load() float64

func (*AtomicFloat64) Set

func (m *AtomicFloat64) Set(val float64)

type Barrier

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

func (*Barrier) Guard

func (m *Barrier) Guard(f func())

type Cond

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

A Cond is used to wait for conditions.

func NewCond

func NewCond() *Cond

func (*Cond) Signal

func (m *Cond) Signal()

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

func (*Cond) Wait

func (m *Cond) Wait()

func (*Cond) WaitWithTimeout

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

WaitWithTimeout wait for signal return remain wait timex or timed out.

type DoneChan

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

A DoneChan is used as a channel that can be closed multiple times and wait for done.

func NewDoneChan

func NewDoneChan() *DoneChan

func (*DoneChan) Close

func (m *DoneChan) Close()

func (*DoneChan) Done

func (m *DoneChan) Done() chan struct{}

type ImmutableResource

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

An ImmutableResource is used to manage an immutable resource.

func NewImmutableResource

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

func (*ImmutableResource) Get

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

Get gets the immutable resource, fetches automatically if not loaded.

type ImmutableResourceOption

type ImmutableResourceOption func(resource *ImmutableResource)

ImmutableResourceOption defines the method to customize an ImmutableResource.

func WithRefreshIntervalOnFailure

func WithRefreshIntervalOnFailure(interval time.Duration) ImmutableResourceOption

WithRefreshIntervalOnFailure sets refresh interval on failure. Set interval to 0 to enforce refresh every timex if not succeeded, default is time.Second.

type Limit

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

func NewLimit

func NewLimit(captity int) Limit

func (Limit) Borrow

func (m Limit) Borrow()

func (Limit) Return

func (m Limit) Return() error

func (Limit) TryBorrrow

func (m Limit) TryBorrrow() bool

type OnceGuard

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

A OnceGuard is used to make sure a resource can be taken once.

func (*OnceGuard) CheckTake

func (m *OnceGuard) CheckTake() bool

CheckTake checks if the resource is taken.

func (*OnceGuard) Take

func (m *OnceGuard) Take() bool

type SpinLock

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

A SpinLock is used as a lock a fast execution.

func (*SpinLock) Lock

func (m *SpinLock) Lock()

func (*SpinLock) TryLock

func (m *SpinLock) TryLock() bool

func (*SpinLock) UnLock

func (m *SpinLock) UnLock()

type TimeoutLimit

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

A TimeoutLimit is used to borrow with timeouts.

func NewTimeoutLimit

func NewTimeoutLimit(n int) TimeoutLimit

NewTimeoutLimit returns a TimeoutLimit.

func (*TimeoutLimit) Borrow

func (m *TimeoutLimit) Borrow(timeout time.Duration) error

func (*TimeoutLimit) Return

func (m *TimeoutLimit) Return() error

func (*TimeoutLimit) TryBorrow

func (m *TimeoutLimit) TryBorrow() bool

Jump to

Keyboard shortcuts

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