use wait group not stopper

This commit is contained in:
Mark Beamer Jr 2021-04-06 14:28:29 -04:00 committed by Niko Storni
parent ed3622d0a6
commit 215103cb33
2 changed files with 6 additions and 5 deletions

View file

@ -11,6 +11,7 @@ import (
"math/big"
"net/http"
"strconv"
"sync"
"time"
"github.com/lbryio/reflector.go/internal/metrics"
@ -70,11 +71,10 @@ func (s *Server) Start(address string) error {
}
r := mux.NewRouter()
r.HandleFunc("/get/{hash}", func(w http.ResponseWriter, r *http.Request) {
waiter := stop.New()
waiter := &sync.WaitGroup{}
waiter.Add(1)
enqueue(&blobRequest{request: r, reply: w, finished: waiter})
select {
case <-waiter.Ch():
}
waiter.Wait()
})
r.HandleFunc("/has/{hash}", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

View file

@ -2,6 +2,7 @@ package http3
import (
"net/http"
"sync"
"github.com/lbryio/reflector.go/internal/metrics"
@ -11,7 +12,7 @@ import (
type blobRequest struct {
request *http.Request
reply http.ResponseWriter
finished *stop.Group
finished *sync.WaitGroup
}
var getReqCh = make(chan *blobRequest)