Skip to content

Instantly share code, notes, and snippets.

@martin-mok
Created October 20, 2022 03:14
Show Gist options
  • Save martin-mok/76e123e6ad6e8ad3c967f48089dc52ee to your computer and use it in GitHub Desktop.
Save martin-mok/76e123e6ad6e8ad3c967f48089dc52ee to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
)
func main() {
letter, number := make(chan bool), make(chan bool)
wg := sync.WaitGroup{}
go func() {
start := 1
for {
number <- true
fmt.Print(start)
start += 1
_, ok := <-letter
if ok == false {
break
}
}
wg.Done()
}()
wg.Add(1)
go func() {
for ch := 'a'; ch < 'f'; ch += 1 {
letter <- true
fmt.Print(string(ch))
_, ok := <-number
if ok == false {
break
}
}
close(letter)
}()
<-letter
wg.Wait()
fmt.Print("\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment