mardi 5 mars 2019

Why is my golang channels hanging whole application?

I made a web application, but sometimes it just getting stuck. if i comment out adding messages to channel it works

import (
    "net/http"

    "github.com/labstack/echo"
)

func consumer() {
    for {
        req := <-requests
        println(req)
    }
}

func requestsHandler(c echo.Context){
    req := c.QueryParam("req")
    requests <- req.(string)
    return c.String(http.StatusOK, req)
}

func main() {
    requests := make(chan string)
    go consumer()
    e := echo.New()

    e.GET("/", requestsHandler)

    e.Logger.Fatal(e.Start(":1323"))
}




Aucun commentaire:

Enregistrer un commentaire