Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:22
Show Gist options
  • Select an option

  • Save dacr/5acd1cb4d0a715c93b2dab03e081bb5c to your computer and use it in GitHub Desktop.

Select an option

Save dacr/5acd1cb4d0a715c93b2dab03e081bb5c to your computer and use it in GitHub Desktop.
go channels directions / published by https://github.com/dacr/code-examples-manager #54f3f203-2caa-46eb-a07b-4fba5375cb62/d34a598312a961f42320695c8c559b47207a594
/*?sr/bin/true; exec /usr/bin/env nix-shell -p go --run "go run $0" #*/
// summary : go channels directions
// keywords : go, channels, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : 54f3f203-2caa-46eb-a07b-4fba5375cb62
// created-on : 2025-03-27T16:32:35+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : nix-shell -p go --run "go run $file"
package main
import "fmt"
func ping(pings chan<- string, message string) {
pings <- message
}
func pong(pings <-chan string, pongs chan<- string) {
msg := <-pings
pongs <- msg
}
func main() {
pings := make(chan string, 1)
pongs := make(chan string, 1)
ping(pings, "go ping pong")
pong(pings, pongs)
fmt.Println(<-pongs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment