github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/examples/timeout/timer/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(3) 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 prep1 := iouring.Timeout(2 * time.Second) 20 prep2 := iouring.Timeout(5 * time.Second) 21 ch := make(chan iouring.Result, 1) 22 if _, err := iour.SubmitRequests([]iouring.PrepRequest{prep1, prep2}, ch); err != nil { 23 panic(err) 24 } 25 26 for i := 0; i < 2; i++ { 27 result := <-ch 28 if err := result.Err(); err != nil { 29 fmt.Println("error: ", err) 30 } 31 fmt.Println(time.Now().Sub(now)) 32 } 33 }