Last active
May 24, 2019 15:25
-
-
Save kardolus/f7398dcf88affe41541cafe681775b76 to your computer and use it in GitHub Desktop.
Concurrency Ideas
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" | |
) | |
func main() { | |
pingchan := make(chan string) | |
// Have a channel per callout group | |
go func() { | |
result := Sequential() | |
pingchan <- result | |
}() | |
// Do the other concurrent calls here | |
// ... | |
// Then receive all the results, may as well be one by one | |
received := <-pingchan | |
fmt.Println(received) | |
} | |
func Sequential() string { | |
return "In Sequence" | |
} |
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" | |
) | |
func main() { | |
pingchan := make(chan string) | |
go ping(pingchan) | |
received := <-pingchan | |
fmt.Println(received) | |
} | |
func ping(message chan string) { | |
message <- "ping" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment