Skip to content

Instantly share code, notes, and snippets.

@tlightsky
Last active March 2, 2019 08:31
Show Gist options
  • Save tlightsky/a67e3ee1360e79432478d0baa4a3cab6 to your computer and use it in GitHub Desktop.
Save tlightsky/a67e3ee1360e79432478d0baa4a3cab6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
)
func main() {
c1 := make(chan bool)
c2 := make(chan bool)
c3 := make(chan bool)
wg := sync.WaitGroup{}
wg.Add(1)
go func (){
n := 1
defer wg.Done()
for {
fmt.Printf("%d", n)
fmt.Printf("%d", n+1)
n += 2
c1 <- true
select {
case <- c2:
case <- c3:
return
}
}
}()
wg.Add(1)
go func (){
m := 'A'
defer wg.Done()
for {
select {
case <- c1:
}
if m >= 'Z' {
close(c3)
return
}
fmt.Printf("%c", m)
fmt.Printf("%c", m+1)
m += 2
c2 <- true
}
}()
wg.Wait()
close(c1)
close(c2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment