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

Handling incoming payloads from the master

As we saw in the previous section, the body of the payload-handling goroutine first registers a disconnect callback with the master stream and then delegates the payload processing to the auxiliary handleMasterPayloads method.

This way, if we suddenly lose the connection to the master, we can simply cancel the job context and cause the job to abort with an error. The following disconnect callback implementation is quite simple:

func (c *workerJobCoordinator) handleMasterDisconnect() {
    select {
    case <-c.jobCtx.Done(): // job already aborted or completed
    default:
        c.cancelJobCtx()
    }
}

The handleMasterPayloads method implements a long-running event processing loop. A select block watches for either ...

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