use wait group not stopper

This commit is contained in:
Mark Beamer Jr 2021-04-06 14:28:29 -04:00
parent b97595311f
commit 25a7fac4f0
No known key found for this signature in database
GPG key ID: 1C314FB89AD76973
2 changed files with 6 additions and 5 deletions

View file

@ -11,6 +11,7 @@ import (
"math/big" "math/big"
"net/http" "net/http"
"strconv" "strconv"
"sync"
"time" "time"
"github.com/lbryio/reflector.go/internal/metrics" "github.com/lbryio/reflector.go/internal/metrics"
@ -70,11 +71,10 @@ 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) {
waiter := stop.New() waiter := &sync.WaitGroup{}
waiter.Add(1)
enqueue(&blobRequest{request: r, reply: w, finished: waiter}) enqueue(&blobRequest{request: r, reply: w, finished: waiter})
select { waiter.Wait()
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)

View file

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