github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/examples/timeout/link-with-timeout/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/iceber/iouring-go" 8 ) 9 10 func main() { 11 iour, err := iouring.New(10) 12 if err != nil { 13 panic(fmt.Sprintf("new IOURing error: %v", err)) 14 } 15 defer iour.Close() 16 17 now := time.Now() 18 19 rs := iouring.Timeout(2 * time.Second).WithTimeout(1 * time.Second) 20 rs1 := iouring.Timeout(5 * time.Second).WithTimeout(4 * time.Second) 21 rs = append(rs, rs1...) 22 23 ch := make(chan iouring.Result, 1) 24 if _, err := iour.SubmitLinkRequests(rs, ch); err != nil { 25 panic(err) 26 } 27 28 for i := 0; i < 2; i++ { 29 result := <-ch 30 if err := result.Err(); err != nil { 31 fmt.Println("error: ", err) 32 } 33 fmt.Println(time.Now().Sub(now)) 34 } 35 }