January 2020
Intermediate to advanced
640 pages
16h 56m
English
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 ...