Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "net/http"
- "sync"
- )
- var (
- URLOK string = "https://google.com"
- URLSLOW string = "http://slowwly.robertomurray.co.uk/delay/10000/url/" + URLOK
- )
- func goSlow(slowURL string, wg *sync.WaitGroup) {
- fmt.Println("in go slow")
- r, _ := http.Get(slowURL)
- defer r.Body.Close()
- defer fmt.Println("GO SLOW", "DONE")
- defer wg.Done()
- }
- func goFast(URL string, wg *sync.WaitGroup) {
- fmt.Println("in go fast")
- r, _ := http.Get(URL)
- defer r.Body.Close()
- defer fmt.Println("GO FAST", "DONE")
- defer wg.Done()
- }
- func justGo(wg *sync.WaitGroup) {
- fmt.Println("in just Go")
- r, _ := http.Get("https://bing.com")
- defer r.Body.Close()
- defer fmt.Println("JUST GO", "DONE")
- defer wg.Done()
- }
- func main() {
- var wg sync.WaitGroup
- wg.Add(3)
- go goSlow(URLSLOW, &wg)
- go justGo(&wg)
- go goFast(URLOK, &wg)
- wg.Wait()
- }
- //Outputs:
- in go fast
- in go slow
- in just Go
- GO FAST DONE
- JUST GO DONE
- GO SLOW DONE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement