combiner

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

README

combiner

GoDoc

Package combiner implements combining-queue for race-free batching of operations.

Documentation

Overview

Package combiner implements combining-queue for race-free batching of operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batcher

type Batcher interface {
	// Start is called on a start of a new batch.
	Start()
	// Do is called for each batch element.
	Do(arg interface{})
	// Finish is called after completing a batch.
	Finish()
}

Batcher is the operation combining implementation.

Batcher must not panic.

type Parking

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

Parking is a bounded non-spinning combiner queue.

This implementation is useful when the batcher work is large ore there are many goroutines concurrently calling Do. A good example would be a appending to a file.

func NewParking

func NewParking(batcher Batcher, limit int) *Parking

NewParking creates a Parking combiner queue

func (*Parking) Do

func (q *Parking) Do(arg interface{})

Do passes value to Batcher and waits for completion

func (*Parking) Init

func (q *Parking) Init(batcher Batcher, limit int)

Init initializes a Parking combiner. Note: NewParking does this automatically.

type Spinning deprecated

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

Spinning is a combiner queue with spinning waiters.

This implementation is useful when the batcher work is small and there are few goroutines concurrently calling Do. A good example would be a shared data-structure.

If very high performance is required benchmark replacing Batcher and argument with concrete implementation.

Deprecated: This may cause problems with OS or runtime scheduler. Use Parking implementation instead.

func NewSpinning

func NewSpinning(batcher Batcher, limit int) *Spinning

NewSpinning creates a spinning combiner with the given limit

func (*Spinning) Do

func (q *Spinning) Do(arg interface{})

Do passes arg safely to batcher and calls Start / Finish. The methods maybe called in a different goroutine.

func (*Spinning) Init

func (q *Spinning) Init(batcher Batcher, limit int)

Init initializes a Spinning combiner. Note: NewSpinning does this automatically.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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