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

Sending and receiving messages

As we mentioned previously, vertices communicate with each other by exchanging messages. Sending the same message to all immediate neighbors of a particular vertex is an often recurring pattern in several graph algorithms. Let's define a convenience method for handling this fairly common use case:

func (g *Graph) BroadcastToNeighbors(v *Vertex, msg message.Message) error {
    for _, e := range v.edges {
        if err := g.SendMessage(e.dstID, msg); err != nil {
            return err
        }
    }

    return nil
}

BroadcastToNeighbors simply iterates the list of edges for a particular vertex and attempts to send the message to each neighbor with the help of the SendMessage method. With the help of SendMessage, compute functions can send a message ...

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