Created
March 28, 2025 09:01
-
-
Save dacr/2d61dd47b2b1874a1a544911b94f5812 to your computer and use it in GitHub Desktop.
go channels synchronization / published by https://github.com/dacr/code-examples-manager #ee0bc7f1-a15e-4e0b-ace2-3ae943691a88/ca0f192d6706e16e3b4ee11f35f89f96a3735581
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 synchronization | |
// keywords : go, channels, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : ee0bc7f1-a15e-4e0b-ace2-3ae943691a88 | |
// created-on : 2025-03-27T16:21:05+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" | |
"time" | |
) | |
func worker(done chan bool) { | |
fmt.Println("starting worker") | |
time.Sleep(100 * time.Millisecond) | |
fmt.Println("Operations done") | |
defer func() { done <- true }() | |
} | |
func main() { | |
done := make(chan bool, 1) | |
go worker(done) | |
<-done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment