Documentation ¶
Overview ¶
Package futures allow adding incomplete computations in contexts and templates. This allows to start the rendering of the template before all the other operations (for example, database queries) had been finished.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Expirable ¶
Expirable manages the retrieval and recalculation of a value that expires after some time
func NewExpirable ¶
NewExpirable creates a new Expirable with the given TTL and generated with the given generator
type ExpirablePool ¶
type ExpirablePool struct {
Expirables []*Expirable
}
ExpirablePool manages the retrieval and recalculation of a pool of values that expires after some time.
func NewExpirablePool ¶
func NewExpirablePool(timeout time.Duration, size int, generator func() interface{}) *ExpirablePool
NewExpirablePool creates a pool of several Expirable, that could be requested concurrently avoiding a bit the overhead of locking a single Expirable for all the requests. Note that potentially the returned values could go out of synchronization.
func (ExpirablePool) Pick ¶
func (p ExpirablePool) Pick() *Expirable
Pick selects an Expirable at random from the pool
func (*ExpirablePool) Read ¶
func (p *ExpirablePool) Read() interface{}
Read reads the value from an Expirable picked at random, and if it has expired then it recalculates the value using the default generator
func (*ExpirablePool) ReadFunc ¶
func (p *ExpirablePool) ReadFunc(f func() interface{}) interface{}
ReadFunc reads the value from an Expirable picked at random, and if it has expired then it recalculates the value using the given generator
type Future ¶
type Future struct {
// contains filtered or unexported fields
}
Future represents an maybe incomplete operation, that is being processed
func NewFuture ¶
func NewFuture(input chan interface{}) *Future
NewFuture creates a Future from an input channel
func NewFutureFunc ¶
func NewFutureFunc(f func() interface{}) *Future
NewFutureFunc creates a Future from a function that returns an interface{}