Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Acceptor ¶
type Acceptor interface { Accept(Keyer) error // Close is called when the Acceptor is no longer required. Close() }
Acceptor is the interface that Lazy will route Keyers to.
type Keyer ¶
type Keyer interface {
Key() string
}
Keyer is the interface of items that Lazy accepts. Key should be a pure function, i.e. it should always return the same key for the same item, regardless of state.
type Lazy ¶
type Lazy struct {
// contains filtered or unexported fields
}
func NewLazy ¶
NewLazy creates a lazy dispatcher. It accepts items, obtains a key for each item by calling its Key method, then sends it to the Acceptor for that key. If an Acceptor does not exist in Lazy yet, it is created using the factory function. Once an Acceptor has been idle for windowSize number of items, it is closed and removed from Lazy.
factory takes the key name and returns either the new Acceptor or an error. The error is returned to the caller of Lazy.Accept. keyCardinality is a guess for how many unique keys there are; it may be 0, in which case a default is used.
factory may be called from multiple goroutines at once. Also, Lazy may create and then close an Acceptor without ever using it.