If you have a single goroutine doing something and want to wait for it to finish before proceeding then you can use example below.


package main

import (

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

go paint(ch)

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


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