serializer

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NoRetry always returns false independently of the number of retries.
	NoRetry = func(int) bool { return false }
)

Functions

This section is empty.

Types

type FunctionQueue

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

func NewFunctionQueue

func NewFunctionQueue(queueSize uint) *FunctionQueue

NewFunctionQueue returns a FunctionQueue that will be used to execute functions in the same order they are enqueued.

func (*FunctionQueue) Enqueue

func (fq *FunctionQueue) Enqueue(f func() error, waitFunc WaitFunc)

Enqueue enqueues the receiving function `f` to be executed by the function queue. Depending on the size of the function queue and the amount of functions queued, this function can block until the function queue is ready to receive more requests. If `f` returns an error, `waitFunc` will be executed and, depending on the return value of `waitFunc`, `f` will be executed again or not. The return value of `f` will not be logged and it's up to the caller to log it properly.

func (*FunctionQueue) Stop added in v1.5.0

func (fq *FunctionQueue) Stop()

Stop stops the function queue from processing the functions on the queue. If there are functions in the queue waiting for them to be processed, they won't be executed.

func (*FunctionQueue) Wait

func (fq *FunctionQueue) Wait(ctx context.Context) error

Wait until the FunctionQueue is stopped, or the specified context deadline expires. Returns the error from the context, or nil if the FunctionQueue was completed before the context deadline.

type WaitFunc added in v1.5.0

type WaitFunc func(nRetries int) bool

WaitFunc will be invoked each time a queued function has returned an error. nRetries will be set to the number of consecutive execution failures that have occurred so far. The WaitFunc must return true if execution must be retried or false if the function must be returned from the queue.

Jump to

Keyboard shortcuts

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