Created
June 25, 2022 03:22
-
-
Save fzdwx/7a97a87308f29bf4a738664861bba5d4 to your computer and use it in GitHub Desktop.
Sequential printing
This file contains 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" | |
"os" | |
) | |
func main() { | |
c1 := make(chan int, 1) | |
c2 := make(chan int, 1) | |
c3 := make(chan int, 1) | |
c4 := make(chan int, 1) | |
c5 := make(chan int, 1) | |
c6 := make(chan int, 1) | |
c1 <- 1 | |
for { | |
select { | |
case <-c1: | |
fmt.Println(1) | |
c2 <- 1 | |
case <-c2: | |
fmt.Println(2) | |
c3 <- 1 | |
case <-c3: | |
fmt.Println(3) | |
c4 <- 1 | |
case <-c4: | |
fmt.Println(4) | |
c5 <- 1 | |
case <-c5: | |
fmt.Println(5) | |
c6 <- 1 | |
case <-c6: | |
fmt.Println(6) | |
os.Exit(0) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment