batchelor

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: BSD-2-Clause Imports: 1 Imported by: 0

README

Go Report Card

Documentation

Overview

Package batchelor implements a generic batching executor. The API is loosely modeled golang.org/x/sync/singleflight.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

type Batch interface {
	Prepare() error
	Process(ops []func() error) error
}

A Batch is a generic unit of work composed of a number of operations that will be executed together.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

A Queue executes operations in batches. While a batch is executing, all new incoming operations are added to a new "inbox" batch. When the current inflight batch finishes executing the inbox batch is executed and new operations will be queued in the next pending batch.

func NewQueue

func NewQueue(newBatch func() Batch) *Queue

NewQueue creates a new queue given a batch construction function.

func (*Queue) Do

func (q *Queue) Do(op func() error) error

Do executes an operation. The call blocks until the operation has been actually executed.

func (*Queue) DoChan

func (q *Queue) DoChan(op func() error) <-chan error

DoChan executes an operation. Once the operation executes, the return value will be sent to the returned channel.

Jump to

Keyboard shortcuts

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