We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main import ( "context" "fmt" "time" ) var ( sleep_time = []int{1, 2, 3, 4} ) func main() { create_n_goroutines_wait_until_one_is_done_and_exit(4) } func create_n_goroutines_wait_until_one_is_done_and_exit(n int) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() for i := 0; i < n; i++ { go work(i, cancel) } <-ctx.Done() } func work(i int, cancel context.CancelFunc) { defer cancel() time.Sleep(time.Duration(sleep_time[i]) * time.Second) fmt.Println("DONE by index: ", i) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: