syncx

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

* @Author: cnzf1 * @Date: 2023-01-09 13:40:11 * @LastEditors: cnzf1 * @LastEditTime: 2023-01-09 13:42:14 * @Description:

* @Author: cnzf1 * @Date: 2022-11-25 16:16:59 * @LastEditors: cnzf1 * @LastEditTime: 2022-11-25 16:22:47 * @Description:

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitReturn = errors.New("someone returned multiple times")

ErrLimitReturn indicates that the more than borrowed elements were returned.

Functions

func Once

func Once(fn 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 (b *AtomicBool) CompareAndSwap(old, val bool) bool

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

func (*AtomicBool) Set

func (b *AtomicBool) Set(v bool)

Set sets the value to v.

func (*AtomicBool) True

func (b *AtomicBool) True() bool

True returns true if current value is true.

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 (f *AtomicFloat64) Add(val float64) float64

Add adds val to current value.

func (*AtomicFloat64) CompareAndSwap

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

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

func (*AtomicFloat64) Load

func (f *AtomicFloat64) Load() float64

Load loads the current value.

func (*AtomicFloat64) Set

func (f *AtomicFloat64) Set(val float64)

Set sets the current value to val.

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 SingleFlight

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

SingleFlight 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 NewSingleFlight

func NewSingleFlight() SingleFlight

NewSingleFlight returns a SingleFlight.

Jump to

Keyboard shortcuts

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