January 2020
Intermediate to advanced
640 pages
16h 56m
English
The 1-to-N broadcasting pattern allows us to support use cases where each incoming payload must to be processed in parallel by N different processors, each one of which implements FIFO-like semantics.
The following code is the definition of the broadcast type and the Broadcast helper function that serves as its constructor:
type broadcast struct { fifos []StageRunner } func Broadcast(procs ...Processor) StageRunner { if len(procs) == 0 { panic("Broadcast: at least one processor must be specified") } fifos := make([]StageRunner, len(procs)) for i, p := range procs { fifos[i] = FIFO(p) } return &broadcast{fifos: fifos} }
As you can see, the variadic Broadcast function receives a list of Processor instances as arguments ...