[GO]go使用contextCancel】的更多相关文章

package main import ( "fmt" "context" ) func main() { gen := func(ctx context.Context) <-chan int { dst := make(chan int) n := go func() { for { select { case <-ctx.Done(): return // returning not to leak the goroutine case dst &…