Skip to content

Instantly share code, notes, and snippets.

@armando-couto
Created December 27, 2021 01:06
Show Gist options
  • Save armando-couto/ecc1b9dd9d5af66cd159309570673285 to your computer and use it in GitHub Desktop.
Save armando-couto/ecc1b9dd9d5af66cd159309570673285 to your computer and use it in GitHub Desktop.
Goroutines
package main
import (
"fmt"
"sync"
)
func main() {
letter, number := make(chan bool), make(chan bool)
wg := sync.WaitGroup{}
go func() {
for ch := 'A'; ch < 'Z'; ch += 1 {
letter <- true
fmt.Print(string(ch))
<-number
}
close(letter)
}()
wg.Add(1)
go func() {
start := 1
for {
number <- true
_, ok := <-letter
if ok == false {
break
}
fmt.Print(start)
start += 1
}
wg.Done()
}()
<-number
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment