相关疑难解决方法(0)

Webhook进程在另一个goroutine上运行

我想在另一个goroutine中运行一些缓慢的例程,这样做是否安全:

func someHandler(w http.ResponseWriter, r *http.Request) {
   go someReallySlowFunction() // sending mail or something slow
   fmt.Fprintf(w,"Mail will be delivered shortly..")
}

func otherHandler(w http.ResponseWriter, r *http.Request) {
   foo := int64(0)
   bar := func() {
      // do slow things with foo
   }
   go bar()
   fmt.Fprintf(w,"Mail will be delivered shortly..")
}
Run Code Online (Sandbox Code Playgroud)

这样做有什么陷阱吗?

http go goroutine server

2
推荐指数
1
解决办法
249
查看次数

标签 统计

go ×1

goroutine ×1

http ×1

server ×1