Documentation ¶
Index ¶
- func EventEvery(lambda time.Duration) func(context.Context) time.Duration
- func EventIntervalAverage(eventCount uint64, simulationDuration time.Duration) time.Duration
- func EventPipe[T any](ctx context.Context, from <-chan Event[T], to chan Event[T])
- func PoissonDuration(lambda time.Duration) time.Duration
- func PoissonF64(lambda float64) float64
- func ReadEvents[T any](ctx context.Context, from <-chan Event[T], to EventHandler[T])
- func SpewEvents[T any](ctx context.Context, from chan Event[T])
- func WaitAll(sources ...Waiter)
- type Event
- type EventHandler
- type EventSource
- type Waiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EventEvery ¶
EventEvery returns an interval provider for an event source that returns a result from `RandomInterval`.
func EventIntervalAverage ¶
EventIntervalAverage yields the average event interval given an even count and total event duration.
func EventPipe ¶
EventPipe pipes events from one channel to another with a background goroutine that can be canceled with the given context.
func PoissonDuration ¶
PoissonDuration returns a poisson distributed random duration value with an average centered around the given lambda.
func PoissonF64 ¶
PoissonF64 generates a random poisson distributed float64 with average given by `lambda`.
func ReadEvents ¶
func ReadEvents[T any](ctx context.Context, from <-chan Event[T], to EventHandler[T])
ReadEvents reads from a given event channel and calls a given handler function for each event.
func SpewEvents ¶
SpewEvents prints events produced by a channel to stdout.
Types ¶
type EventHandler ¶
EventHandler is a method that receives events from `EventHandle`.
type EventSource ¶
type EventSource[T any] struct { Count uint64 StopAfter time.Duration Interval func(context.Context) time.Duration EventFactory func(context.Context) T // contains filtered or unexported fields }
EventSource helps produce events given an interval.
You must provide both an `Interval` delegate AND an `Event` delegate.
func (*EventSource[T]) Start ¶
func (es *EventSource[T]) Start(ctx context.Context, realtime bool) <-chan Event[T]
Start begins the event source in either "simulation" or "realtime" mode.
"Simulation" mode is enabled by passing `false` a the `realtime` flag and produces messages with no real-world delay.
"Realtime" mode waits the given intervals between events.
In this mode it will publish the events to a channel based on poisson distributed arrival times.
The call does not block, and instead starts a background goroutine which you can cancel with the given context.
func (EventSource[T]) Wait ¶
func (es EventSource[T]) Wait()
Wait waits for the event source to finish producing.