Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

1-to-N broadcasting

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content