Go を少しいじっていますが、解決できない問題があります。
次のコードは、私の問題を再現する可能性が最も低いコードです。元のコードの目的は、http リクエストをゴルーチンに委譲することです。各ゴルーチンは少し重い画像計算を行い、応答することになっています。
package main
import (
"fmt"
"runtime"
"net/http"
)
func main() {
http.HandleFunc("/", handle)
http.ListenAndServe(":8080", nil)
}
func handle(w http.ResponseWriter, r *http.Request) {
// the idea is to be able to handle several requests
// in parallel
// the "go" is problematic
go delegate(w)
}
func delegate(w http.ResponseWriter) {
// do some heavy calculations first
// present the result (in the original code, the image)
fmt.Fprint(w, "hello")
}
の場合はgo delegate(w)
応答がありませんが、 がないgo
とうまくいきます。
誰が何が起こっているのか説明できますか? どうもありがとう!