Wait for request to be handled before returning
This commit is contained in:
parent
bd13836897
commit
b97595311f
2 changed files with 9 additions and 3 deletions
|
@ -70,7 +70,11 @@ func (s *Server) Start(address string) error {
|
||||||
}
|
}
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
r.HandleFunc("/get/{hash}", func(w http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/get/{hash}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
enqueue(&blobRequest{request: r, reply: w})
|
waiter := stop.New()
|
||||||
|
enqueue(&blobRequest{request: r, reply: w, finished: waiter})
|
||||||
|
select {
|
||||||
|
case <-waiter.Ch():
|
||||||
|
}
|
||||||
})
|
})
|
||||||
r.HandleFunc("/has/{hash}", func(w http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/has/{hash}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
|
@ -9,8 +9,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type blobRequest struct {
|
type blobRequest struct {
|
||||||
request *http.Request
|
request *http.Request
|
||||||
reply http.ResponseWriter
|
reply http.ResponseWriter
|
||||||
|
finished *stop.Group
|
||||||
}
|
}
|
||||||
|
|
||||||
var getReqCh = make(chan *blobRequest)
|
var getReqCh = make(chan *blobRequest)
|
||||||
|
@ -37,4 +38,5 @@ func enqueue(b *blobRequest) {
|
||||||
|
|
||||||
func process(server *Server, r *blobRequest) {
|
func process(server *Server, r *blobRequest) {
|
||||||
server.HandleGetBlob(r.reply, r.request)
|
server.HandleGetBlob(r.reply, r.request)
|
||||||
|
r.finished.Done()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue