Created
December 16, 2019 19:20
-
-
Save spddl/1084b1bf47f65dde1d987772a92db0be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://pragmacoders.com/blog/multithreading-in-go-a-tutorial | |
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
func main() { | |
rand.Seed(time.Now().UTC().UnixNano()) | |
query := "Our Query" | |
respond := make(chan string) | |
go googleIt(respond, query) | |
queryResp := <-respond | |
fmt.Printf("Sent query:\t\t %s\n", query) | |
fmt.Printf("Got Response:\t\t %s\n", queryResp) | |
} | |
func googleIt(respond chan<- string, query string) { | |
time.Sleep(time.Duration(rand.Intn(10)) * time.Second) | |
respond <- "A Google Response" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment