conductor

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package conductor is a small helper to execute work heavy operations in the backgrounds that deliver partial results ("result streaming").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNoDataLeft

func IsNoDataLeft(err error) bool

IsNoDataLeft returns true if `err` is a ErrNoDataLeft error.

func IsNoSuchTicket

func IsNoSuchTicket(err error) bool

IsNoSuchTicket returns true if `err` is a ErrNoSuchTicket error.

Types

type Conductor

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

Conductor (as in train conductor) yields tickets for jobs. There are three operations: - Exec: Execute heavy work in the background, caller get's a ticket. - Push: Report partial results of the heavy work. - Pull: Fetch a partial result from the caller side via the ticket.

Tickets are only job ids, i.e. plain integers. The concept is similar to futures, but the result will clean up themselves after a certain timeout.

func New

func New(timeout time.Duration, maxData int) *Conductor

New creates a new conductor that will expire unfetched results after `timeout` and will hold at max `maxData` partial results in memory.

func (*Conductor) Exec

func (cd *Conductor) Exec(fn func(ticket uint64) error) uint64

Exec executes `fn` in the background. `fn` gets the current ticket and can use it to push partial results using Push(). Exec will return a ticket number that can be used by the caller to Pull() partial results until ErrNoDataLeft is returned.

func (*Conductor) Pop

func (cd *Conductor) Pop(ticket uint64) (interface{}, error)

Pop gets the first (FIFO) partial result associated with `ticket`. It will return ErrNoDataLeft if there won't be any more values. It will return ErrNoSuchTicket if you passed an invalid ticket.

func (*Conductor) Push

func (cd *Conductor) Push(ticket uint64, data interface{}) error

Push records a new partial result under a specific `ticket`. Push will block after pushing more than `maxData` items.

type ErrNoDataLeft

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

ErrNoDataLeft is returned by Pop() if there is no data left to be returned. This will only happen if the exec func returned and there are no cached results.

func (ErrNoDataLeft) Error

func (end ErrNoDataLeft) Error() string

type ErrNoSuchTicket

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

ErrNoSuchTicket will be returned by Push() or Pop() if there is no such ticket with this id. This will be also returned when accessing a previously expired ticket.

func (ErrNoSuchTicket) Error

func (ens ErrNoSuchTicket) Error() string

Jump to

Keyboard shortcuts

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