-
-
Save c93614/4573433 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func callA() string { | |
time.Sleep(time.Millisecond * 300) | |
return "Hello A" | |
} | |
func callB() string { | |
time.Sleep(time.Millisecond * 100) | |
return "Hello B" | |
} | |
func callC() string { | |
time.Sleep(time.Millisecond * 200) | |
return "Hello C" | |
} | |
func main() { | |
a_is_done := make(chan bool) | |
b_is_done := make(chan bool) | |
go func() { | |
log.Println(callA()) | |
a_is_done <- true | |
}() | |
go func() { | |
log.Println(callB()) | |
go func() { | |
log.Println(callC()) | |
}() | |
b_is_done <- true | |
}() | |
t := time.Now() | |
<-a_is_done //wait for A to finish or timeout | |
select { | |
case <-b_is_done: | |
case <-time.After(time.Duration(time.Millisecond*200) - time.Now().Sub(t)): //todo: duration <= 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment