Documentation
¶
Index ¶
- type Group
- func (g *Group[K, V]) Do(key K, fn func() (V, error)) (v V, err error, shared bool)
- func (g *Group[K, V]) DoChan(key K, fn func() (V, error)) <-chan Result[V]
- func (g *Group[K, V]) DoChanX(keys []K, fn func([]K) (map[K]V, error)) map[K]chan Result[V]
- func (g *Group[K, V]) DoX(keys []K, fn func([]K) (map[K]V, error)) (results map[K]Result[V])
- func (g *Group[K, V]) Forget(key K)
- func (g *Group[K, V]) ForgetX(keys []K)
- type Hasher
- type NullValue
- type Result
- type ShardedGroup
- func (sg *ShardedGroup[K, V]) Do(key K, fn func() (V, error)) (v V, err error, shared bool)
- func (sg *ShardedGroup[K, V]) DoChan(key K, fn func() (V, error)) <-chan Result[V]
- func (sg *ShardedGroup[K, V]) DoChanX(keys []K, fn func([]K) (map[K]V, error)) map[K]chan Result[V]
- func (sg *ShardedGroup[K, V]) DoX(keys []K, fn func([]K) (map[K]V, error)) (results map[K]Result[V])
- func (sg *ShardedGroup[K, V]) Forget(key K)
- func (sg *ShardedGroup[K, V]) ForgetX(keys []K)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group[K comparable, V any] struct { // contains filtered or unexported fields }
Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.
func (*Group[K, V]) Do ¶
Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results. The return value shared indicates whether v was given to multiple callers.
func (*Group[K, V]) DoChan ¶
DoChan is like Do but returns a channel that will receive the results when they are ready.
The returned channel will not be closed.
func (*Group[K, V]) DoChanX ¶
DoChanX is like Do but returns a channel that will receive the results when they are ready.
The returned channel will not be closed.
func (*Group[K, V]) DoX ¶
DoX executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results. The return value shared indicates whether v was given to multiple callers. Even if fn does not return V on some keys, the results map will contain those keys with a `Valid` field set to false.
type Hasher ¶ added in v0.2.0
Hasher is responsible for generating unsigned, 16 bit hash of provided key. Hasher should minimize collisions. For great performance, a fast function is preferable.
type ShardedGroup ¶ added in v0.2.0
type ShardedGroup[K comparable, V any] struct { // contains filtered or unexported fields }
ShardedGroup is a duplicate of singleflight.Group, but with the ability to shard the map of calls.
func NewShardedGroup ¶ added in v0.2.0
func NewShardedGroup[K comparable, V any](count uint, hasher Hasher[K]) *ShardedGroup[K, V]
func (*ShardedGroup[K, V]) Do ¶ added in v0.2.0
func (sg *ShardedGroup[K, V]) Do(key K, fn func() (V, error)) (v V, err error, shared bool)
Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results. The return value shared indicates whether v was given to multiple callers. Even if fn does not return V on some keys, the results map will contain those keys with a `Valid` field set to false.
func (*ShardedGroup[K, V]) DoChan ¶ added in v0.2.0
func (sg *ShardedGroup[K, V]) DoChan(key K, fn func() (V, error)) <-chan Result[V]
DoChan is like Do but returns a channel that will receive the results when they are ready.
The returned channel will not be closed.
func (*ShardedGroup[K, V]) DoChanX ¶ added in v0.2.0
func (sg *ShardedGroup[K, V]) DoChanX(keys []K, fn func([]K) (map[K]V, error)) map[K]chan Result[V]
DoChanX is like Do but returns a channel that will receive the results when they are ready.
The returned channel will not be closed.
func (*ShardedGroup[K, V]) DoX ¶ added in v0.2.0
func (sg *ShardedGroup[K, V]) DoX(keys []K, fn func([]K) (map[K]V, error)) (results map[K]Result[V])
DoX executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results. The return value shared indicates whether v was given to multiple callers.
func (*ShardedGroup[K, V]) Forget ¶ added in v0.3.0
func (sg *ShardedGroup[K, V]) Forget(key K)
Forget tells the singleflight to forget about a key. Future calls to Do for this key will call the function rather than waiting for an earlier call to complete.
func (*ShardedGroup[K, V]) ForgetX ¶ added in v0.3.0
func (sg *ShardedGroup[K, V]) ForgetX(keys []K)
ForgetX tells the singleflight to forget about many keys. Future calls to Do for this key will call the function rather than waiting for an earlier call to complete.