Skip to content

Instantly share code, notes, and snippets.

@micahwalter
Created November 3, 2023 17:16
Show Gist options
  • Save micahwalter/ca87a494902f84990b8898fe6b82db90 to your computer and use it in GitHub Desktop.
Save micahwalter/ca87a494902f84990b8898fe6b82db90 to your computer and use it in GitHub Desktop.
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