batchque

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package batchque provides functionality for managing and canceling batches of requests.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("use of closed connection")

Functions

func CancelFunc

func CancelFunc[K comparable, V any](err error, rr []Request[K, V])

CancelFunc cancels a batch of requests by concurrently calling the CancelFunc method on each request.

Types

type Group

type Group[In, Out any] struct {
	// contains filtered or unexported fields
}

Group is a generic type that manages batching of requests. It collects individual requests with the same input and output types, groups them together, and processes them in batches using a provided function.

func (*Group[In, Out]) Do

func (g *Group[In, Out]) Do(ctx context.Context, key In, f func(context.Context, []Request[In, Out])) (Out, error)

Do submits a request with the given key to be processed in a batch. It returns the result of processing the request or an error.

func (*Group[In, Out]) Stop

func (g *Group[In, Out]) Stop()

Stop shuts down the Group's processing loop and waits for it to complete. Once closed, no new requests can be accepted. This method is safe to call multiple times.

type Request

type Request[V, R any] struct {
	Val        V        // Input
	C          chan<- R // Result
	CancelFunc context.CancelCauseFunc
	// contains filtered or unexported fields
}

Request represents a single operation within a batch. It contains the input value, a channel to receive the result, and context management for cancellation.

func (Request[V, R]) Context

func (r Request[V, R]) Context() context.Context

Context returns the context associated with this request. If no context was provided, it returns context.Background().

Jump to

Keyboard shortcuts

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