ion: github.com/estebarb/ion/futures Index | Files

package futures

import "github.com/estebarb/ion/futures"

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

Package Files

expirable.go futures.go

func Read Uses

func Read(f *Future) interface{}

Read reads the Future value. Is intended to be used on templates.

type Expirable Uses

type Expirable struct {
    sync.Mutex
    // contains filtered or unexported fields
}

Expirable manages the retrieval and recalculation of a value that expires after some time

func NewExpirable Uses

func NewExpirable(timeout time.Duration, generator func() interface{}) *Expirable

NewExpirable creates a new Expirable with the given TTL and generated with the given generator

func (*Expirable) Read Uses

func (e *Expirable) Read() interface{}

Read returns the current value of the Expirable, and if it has expired then it recalculates the value using the default generator

func (*Expirable) ReadFunc Uses

func (e *Expirable) ReadFunc(f func() interface{}) interface{}

ReadFunc returns the current value of the Expirable, and if it has expired then it recalculates the value using the given generator

type ExpirablePool Uses

type ExpirablePool struct {
    Expirables []*Expirable
}

ExpirablePool manages the retrieval and recalculation of a pool of values that expires after some time.

func NewExpirablePool Uses

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 Uses

func (p ExpirablePool) Pick() *Expirable

Pick selects an Expirable at random from the pool

func (*ExpirablePool) Read Uses

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 Uses

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 Uses

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

Future represents an maybe incomplete operation, that is being processed

func NewFuture Uses

func NewFuture(input chan interface{}) *Future

NewFuture creates a Future from an input channel

func NewFutureFunc Uses

func NewFutureFunc(f func() interface{}) *Future

NewFutureFunc creates a Future from a function that returns an interface{}

func (*Future) Read Uses

func (f *Future) Read() interface{}

Read blocks until the computation finish, and then returns the value.

Package futures imports 3 packages (graph) and is imported by 1 packages. Updated 2017-01-10. Refresh now. Tools for package owners.