February 2018
Intermediate to advanced
246 pages
6h 3m
English
We know that goroutines run across multiple threads and multiple cores. So what happens when we have a panic in one of the threads? Here is an example that would let us simulate such a situation. We will create a lot of similar goroutines, whose sole purpose is to take a number and divide it by itself after subtracting 10 from the denominator. This will work fine for the majority of cases, except when the number is 10. The following code implements the described functionality:
package main import ( "fmt" "sync" ) func simpleFunc(index int, wg *sync.WaitGroup) { // This line should fail with Divide By Zero when index = 10 fmt.Println("Attempting x/(x-10) where x = ", index, " answer is : ", index/(index-10)) ...Read now
Unlock full access