Created
October 20, 2022 03:14
-
-
Save martin-mok/76e123e6ad6e8ad3c967f48089dc52ee 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
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