github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/examples/timeout/request-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  	now := time.Now()
    17  
    18  	ch := make(chan iouring.Result, 1)
    19  	prepRequests := iouring.Timeout(2 * time.Second).WithTimeout(1 * time.Second)
    20  	_, err = iour.SubmitRequests(prepRequests, ch)
    21  	if err != nil {
    22  		panic(err)
    23  	}
    24  
    25  	result := <-ch
    26  	if err := result.Err(); err != nil {
    27  		fmt.Println("error: ", err)
    28  	}
    29  	fmt.Println(time.Now().Sub(now))
    30  }