batch

package module
v0.0.0-...-3fe3421 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

README

batch

Tools for synchronizing batch requests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batcher

type Batcher[K, V, T any] struct {
	NewLoader func() Loader[K, V, T]
	Duration  time.Duration
	// contains filtered or unexported fields
}

func (*Batcher[K, V, T]) Load

func (b *Batcher[K, V, T]) Load(ctx context.Context, key K) (V, error)

type Loader

type Loader[K, V, T any] interface {
	// CanAdd returns whether or not the key can be added to the batch without
	// exceeding its capacity.
	CanAdd(key K) bool

	// Add adds the key to the batch and returns a token that can be used to
	// retrieve the resulting value after Flush is called.
	Add(key K) (token T)

	// Flush is called only once after which no further calls to CanAdd or Add
	// will be made.
	Flush(ctx context.Context) error

	// Load returns the value for the given token and will only be called after
	// Flush if it does not return an error. Load must be safe to call
	// concurrently.
	Load(token T) (value V, err error)
}

Jump to

Keyboard shortcuts

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