Use a done channel to signal completion by creating a buffered channel, sending a signal when the task finishes, and receiving it in the main goroutine to wait for termination.
package main
import "fmt"
func main() {
done := make(chan struct{})
go func() {
// Simulate work
fmt.Println("Working...")
close(done) // Signal completion
}()
<-done // Wait for signal
fmt.Println("Done")
}