Last active
February 3, 2026 20:19
-
-
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
This file contains hidden or 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
| /*?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