Bir şey yapan tek bir goroutine varsa ve devam etmeden önce işini bitirmesini beklemek istiyorsanız, aşağıdaki örneği kullanabilirsiniz.


Örnek


package main

import (
"fmt"
"time"
)

func main() {
ch := make(chan bool)

go paint(ch)

// Acquire lock by waiting for channel to send something.
<- ch

fmt.Println("done")
}

func paint(ch chan <- bool) {
fmt.Println("started painting")

time.Sleep(2 * time.Second)

fmt.Println("finished painting")

// Instruct to release lock by sending a message.
ch <- true
}

started painting
finished painting
done