Skip to content

Instantly share code, notes, and snippets.

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

  • Save dacr/7782218304879c1e130e18643a2b76a5 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/7782218304879c1e130e18643a2b76a5 to your computer and use it in GitHub Desktop.
go channels buffering / published by https://github.com/dacr/code-examples-manager #c0b7c67c-1366-4b78-983f-1736abbf5a89/bedafbfe65cc4fccb63ad219e3b48d836266040
/*?sr/bin/true; exec /usr/bin/env nix-shell -p go --run "go run $0" #*/
// summary : go channels buffering
// 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 : c0b7c67c-1366-4b78-983f-1736abbf5a89
// created-on : 2025-03-27T16:18:41+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 main() {
ch := make(chan int, 2)
defer close(ch)
ch <- 42
ch <- 43
fmt.Println(<-ch)
fmt.Println(<-ch)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment