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 ( "fmt" "time" "golang.org/x/net/context" ) func main() { ctx, cancel := context.WithCancel(context.Background()) c2 := make(chan string, 1) go func(ctx context.Context) { for { select { case <-ctx.Done(): fmt.Println("监控退出,停止了...") return default: fmt.Println("goroutine监控中...") time.Sleep(2 * time.Second) if 2==2{ c2 <- "Wait repo sync end, repo sync successful ..." } } } }(ctx) // time.Sleep(10 * time.Second) select { case res := <-c2: cancel() fmt.Println(res) case <-time.After(10 * time.Second): fmt.Println("Wait repo sync timeout ...") fmt.Println("可以了,通知监控停止") cancel() return } //为了检测监控过是否停止,如果没有监控输出,就表示停止了 fmt.Println("下载中...") time.Sleep(5 * time.Second) }
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: