dataloader

package
v0.0.0-...-57f3b98 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("dataloader: key not found")
	ErrKeyRejected = errors.New("dataloader: key rejected")
)

Functions

func KeyNotFoundError

func KeyNotFoundError(k any) error

func KeyRejectedError

func KeyRejectedError(k any) error

Types

type DataLoader

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

func New

func New[K comparable, V any](opt Option[K, V]) *DataLoader[K, V]

func (*DataLoader[K, V]) Load

func (d *DataLoader[K, V]) Load(ctx context.Context, k K) Promise[V]

func (*DataLoader[K, V]) LoadMany

func (d *DataLoader[K, V]) LoadMany(ctx context.Context, ks []K) Promises[V]

func (*DataLoader[K, V]) Set

func (d *DataLoader[K, V]) Set(ctx context.Context, k K, v V)

Set sets the key-value after expiring existing references.

func (*DataLoader[K, V]) SetNX

func (d *DataLoader[K, V]) SetNX(ctx context.Context, k K, v V) bool

SetNX sets the key-value, only if the entry does not exists. This prevents issue with references.

func (*DataLoader[K, V]) Stop

func (d *DataLoader[K, V]) Stop()

type Option

type Option[K comparable, V any] struct {
	BatchMaxKeys int
	BatchTimeout time.Duration
	IdleTimeout  time.Duration
	BatchFn      batchFunc[K, V]
	KeyFn        keyFunc[K, V]
	PromiseFn    promiseFn[V]
}

type Promise

type Promise[T any] interface {
	Await() (T, error)
}

func Copier

func Copier[T any](p Promise[T]) Promise[T]

type Promises

type Promises[T any] []Promise[T]

func (Promises[T]) Await

func (promises Promises[T]) Await() ([]T, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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