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" "sync" "time" "github.com/goplus/llgo/c" ) func timeout(d time.Duration) <-chan struct{} { ch := make(chan struct{}) go func() { c.Usleep(c.Uint(d.Microseconds())) close(ch) }() return ch } func main() { ch := make(chan int) var wg sync.WaitGroup // Start a receiver goroutine go func() { for i := 0; i < 2; i++ { select { case v := <-ch: fmt.Printf("Received: %d\n", v) case <-timeout(time.Second): fmt.Println("Receive timeout") } } }() for i := 0; i < 2; i++ { wg.Add(1) go func(id int) { defer select { case ch <- id: defer fmt.Printf("Sent value: %d\n", id) case <-timeout(time.Millisecond * 100): defer fmt.Printf("Timeout for: %d\n", id) } wg.Done() }(i) } wg.Wait() close(ch) // Close the channel after all goroutines are done }
The text was updated successfully, but these errors were encountered:
Same as #694
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: