package main
var fooRunning = false
var barRunning = false
func foo() {
fooRunning = true
defer func() { fooRunning = false }()
if barRunning {
// wait for bar() to finish
}
...
}
func bar() {
barRunning = true
defer func() { barRunning = false }()
if fooRunning {
// wait for foo() to finish
}
...
}
In my case if we run go foo()
it should wait for bar()
to finish and vice versa. What is the best way to do it? Note that they also can be executed independently.