This repo is based on the Rob Pike video on Golang's Concurrency patterns called: Google I/O 2012 - Go Concurrency Patterns.
-
Non Concurrent
This branch just has a simple project that doesn't take advantage of go routines or channels. -
Go Routine
Here we can see how to use go routines to run functions in the background. -
Go Routines while main continues
Here we show how you can run a go routine in the background while main continues to execute. -
Using Channels to communicate
Here you learn to use channels to communicate between concurrently executing code. -
The Generator Pattern
Here you learn how to use the Generator Pattern to simplify how the client receives data from another func by putting the go rountine in the function generating the data instead of in the client (the client being main in this case). In Go, a Generator is a function that returns a channel. -
Using a Generator to create service-like functions
In this section we make use of the generator by lanuching it twice in the background. -
Using the Fan In pattern
In this section we see how we can use the FanIn Pattern to receive all of the results from the services from 1 channel. Here we also use a wait channel in order to syncronize the data we receive from the services. -
Using Select
Here we learn how to use Select instead of using multiple go routines in the fanIn function making the function easier to read. Select is like a switch statement but it performs the first communication case available, this allows you to perform different operations depending on the first communication available. -
Select with Timeout
In the section we make use of the time.After function that creates a channel and returns a value after the time has elapsed. This allows us to use Select as a way to timeout communications that are taking longer than expected. In this case we are using a time.After channel to detect when a single communication channel is taking too long, meaning during each execution of the loop, we restart the timer. However, in This section we use the time.after function to timeout after the total time elapsed, meaning we do not restart the timer for each iteration of the loop. -
Select with Quit Channel
Here we learn how to stop a service using a quit channel allowing you to stop a service -
Select with Quit channel and Cleanup
In this section we add to the quit channel by allowing the service to run some code before it stops in case it needs to perform some cleanup code before exiting. -
Daisy Chaining
Here we show a simple example of how you can daisy chain together channels and run thousands of go routines to pass data from one end of a chain to the other in seconds. This showcases how lightweight the go rountines are. -
Google Search
In this section we start to build out a simplified idea of a search engine where from a single query multiple searches are made, one for web content another for video and then images and then we print out how long the search for all 3 results took. -
Google Search Concurrently
Here we apply the Fan In approach where we start up all 3 searches in separate go routines and receive the individual results in a channel. -
Google Search with Timeout
Here we use the Select plus Timeout pattern to timeout and return only the results that too less than 80 milliseconds. This would mena that we can guarantee that you will get a response back within 80 milliseconds, however it might not have results from all three services. -
Google Search with Replicated Services
Here we explore starting multiple of each service to try and get the quickest response possible. -
Putting it all together
In this section, we put together all of the previous concepts to increase the chances of getting results from all 3 services within 80 milliseconds.