cutter

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: Apache-2.0 Imports: 3 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchCutter

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

BatchCutter implements batch cutting

func New

func New(client protocol.Client, queue OperationQueue) *BatchCutter

New creates a Cutter implementation

func (*BatchCutter) Add

func (r *BatchCutter) Add(operation *batch.OperationInfo) (uint, error)

Add adds the given operation to pending batch queue and returns the total number of pending operations.

func (*BatchCutter) Cut

func (r *BatchCutter) Cut(force bool) ([]*batch.OperationInfo, uint, Committer, error)

Cut returns the current batch along with number of items that should be remaining in the queue after the committer is called. If force is false then the batch will be cut only if it has reached the max batch size (as specified in the protocol) If force is true then the batch will be cut if there is at least one Data in the batch Note that the operations are removed from the queue when the committer is invoked, otherwise they remain in the queue.

type Committer added in v0.1.3

type Committer = func() (pending uint, err error)

Committer is invoked to commit a batch Cut. The new number of pending items in the queue is returned.

type OperationQueue added in v0.1.3

type OperationQueue interface {
	// Add adds the given operation to the tail of the queue and returns the new length of the queue
	Add(data *batch.OperationInfo) (uint, error)
	// Remove removes (up to) the given number of operations from the head of the queue. The operation are returned
	// along with the new length of the queue.
	Remove(num uint) ([]*batch.OperationInfo, uint, error)
	// Peek returns (up to) the given number of operations from the head of the queue but does not remove them.
	Peek(num uint) ([]*batch.OperationInfo, error)
	// Len returns the number of operation in the queue
	Len() uint
}

OperationQueue defines the functions for adding and removing operations from a queue

Jump to

Keyboard shortcuts

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