Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
A Config structure is used to configure the Funnel
type Funnel ¶
The purpose of Funnel is to prevent running of identical operations in concurrently. when receiving requests for a specific operation when an identical operation already in process, the other operation requests will wait until the end of the operation and then will use the same result.
func New ¶
Return a pointer to a new Funnel. By default the timeout is one minute and the cacheTtl is 0. You can pass options to change it, for example:
// Create Funnel with cacheTtl of 5 seconds and timeout of 3 minutes. funnel.New(funnel.WithCacheTtl(time.Second*5),funnel.WithTimeout(time.Minute*3))
func (*Funnel) Execute ¶
func (f *Funnel) Execute(operationId string, opExeFunc func() (interface{}, error)) (res interface{}, err error)
Execute receives an identifier of the operation and a callback function to execute. The first request to funnel with this identifier will result in the callback function being executed in a new goroutine. All other requests (with the same identifier) will wait for the result of the first execution. IMPORTANT: The returned object is shared between all the requesting callers. Use ExecuteAndCopyResult to return a dedicated (copied) object.
func (*Funnel) ExecuteAndCopyResult ¶
func (f *Funnel) ExecuteAndCopyResult(operationId string, opExeFunc func() (interface{}, error)) (res interface{}, err error)
IMPORTANT: Only exported field values can be copied over.
func (*Funnel) IsOpInProgress ¶
type Option ¶
type Option func(*Config)
func WithCacheTtl ¶
WithCacheTtl defines the time for which the result can remain cached (the default is 0 )
func WithShouldCachePredicate ¶ added in v1.0.2
WithShouldCachePredicate allows more control over which responses should be cached. If this option is used responses from execute will only be cached if the predicate provided returns true.
func WithTimeout ¶
WithTimeout defines the maximum time that goroutines will wait for ending of operation (the default is one minute)