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 ¶
var ErrLimitReturn = errors.New("someone returned multiple times")
ErrLimitReturn indicates that the more than borrowed elements were returned.
Functions ¶
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 (*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) 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) 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 (Limit) Borrow ¶
func (l Limit) Borrow()
Borrow borrows an element from Limit in blocking mode.
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