Skip to Content
Learning Functional Programming in Go
book

Learning Functional Programming in Go

by Lex Sheehan
November 2017
Intermediate to advanced
670 pages
17h 35m
English
Packt Publishing
Content preview from Learning Functional Programming in Go

Using channels to manage the life cycle

We use three channels to manage the life cycle of our requestor component:

  • responseChan chan *response
  • stopChan chan struct{}
  • interruptChan := make(chan os.Signal, 1)

Every 5,000 milliseconds, we check responseChan to see whether we've received a new response. If so, we print a message indicating that the request is completed.

First, stopChan is used to stop the running of the displayProgress function.

Then, interruptChan is used to signal everything to shut down when the user presses Ctrl + C.

The Run method of Job makes all the requests, displays summary results, and blocks until all responses are received:

func (j *Job) Run() {       j.responseChan = make(chan *response, j.NumRequests) stopChan := make( ...
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

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781787281394Supplemental Content