Skip to content

Instantly share code, notes, and snippets.

@dacr
Created March 28, 2025 09:01
Show Gist options
  • Save dacr/2d61dd47b2b1874a1a544911b94f5812 to your computer and use it in GitHub Desktop.
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
/*?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