Created
November 3, 2023 17:16
-
-
Save micahwalter/ca87a494902f84990b8898fe6b82db90 to your computer and use it in GitHub Desktop.
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" | |
"time" | |
) | |
func longBlockingProcess(s string) { | |
fmt.Printf("Starting blocking process for %v\n", s) | |
time.Sleep(10 * time.Second) | |
fmt.Printf("Blocking process for %v finished\n", s) | |
} | |
func longRunningProcess(s string, c chan string) { | |
fmt.Printf("Starting running process for %v\n", s) | |
time.Sleep(10 * time.Second) | |
c <- s + ": done." | |
} | |
func main() { | |
longBlockingProcess("Process A") | |
go longBlockingProcess("Process B") | |
c := make(chan string) | |
go longRunningProcess("Process C", c) | |
go longRunningProcess("Process D", c) | |
fmt.Println(<-c) | |
fmt.Println(<-c) | |
fmt.Println("Exiting") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment