package main
import (
"context"
"fmt"
"time"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.GET("/asy", exec)
router.Run()
}
func exec(c *gin.Context) {
go func() {
message := dowork()
fmt.Println(message)
}()
}
func dowork() string {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
ticker := time.NewTicker(time.Second)
for {
select {
case <-ticker.C:
fmt.Println("ticker")
case <-ctx.Done():
return "finish"
}
}
return ""
}