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 ¶
IsNoDataLeft returns true if `err` is a ErrNoDataLeft error.
func IsNoSuchTicket ¶
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 ¶
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 ¶
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.
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