singleflight

package
v1.7.15 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package singleflight provides a duplicate function call suppression mechanism.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group[V any] interface {
	Do(ctx context.Context, key string, fn func(context.Context) (V, error)) (v V, shared bool, err error)
	DoChan(ctx context.Context, key string, fn func(context.Context) (V, error)) <-chan Result[V]
	Forget(key string)
}

Group represents interface for zero time cache.

Example
Output:

Shared: true
Equal results: true
Result: func 1

func New

func New[V any]() Group[V]

New returns Group implementation.

type Result

type Result[V any] struct {
	Val    V
	Err    error
	Shared bool
}

Result holds the results of Do, so they can be passed on a channel.

Jump to

Keyboard shortcuts

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