dataloader

package
v0.0.0-...-afa5e5b Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Unlicense Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoValueError = errors.New("<dataloader: no value>")

Functions

This section is empty.

Types

type BatchFunc

type BatchFunc[K comparable, V any] func([]context.Context, []K) map[K]Result[V]

BatchFunc is a function, which when given a slice of keys (string), returns a map of `results` indexed by keys.

The keys passed to this function are guaranteed to be unique.

type Loader

type Loader[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Loader implements the dataloader.Interface.

func NewBatchedLoader

func NewBatchedLoader[K comparable, V any](batchFn BatchFunc[K, V], opts Options) *Loader[K, V]

NewBatchedLoader constructs a new Loader with given options.

func (*Loader[K, V]) Load

func (l *Loader[K, V]) Load(ctx context.Context, key K) (value V, err error)

Load load/resolves the given key, returning a channel that will contain the value and error. The first context passed to this function within a given batch window will be provided to the registered BatchFunc.

type Options

type Options struct {
	Wait         time.Duration
	MaxThreshold uint
}

type Result

type Result[V any] struct {
	Data  V
	Error error
}

Result is the data structure that a BatchFunc returns. It contains the resolved data, and any errors that may have occurred while fetching the data.

Jump to

Keyboard shortcuts

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