good morning!!!!

Skip to content
Snippets Groups Projects
Commit ccf8e35f authored by Garet Halliday's avatar Garet Halliday
Browse files

the good kind of race

parent 8489e348
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ package request ...@@ -3,7 +3,7 @@ package request
import ( import (
"gfx.cafe/gfx/pggat/lib/gat2/request" "gfx.cafe/gfx/pggat/lib/gat2/request"
"gfx.cafe/gfx/pggat/lib/gat2/sink" "gfx.cafe/gfx/pggat/lib/gat2/sink"
"math/rand" "gfx.cafe/gfx/pggat/lib/util/race"
) )
type Pool struct { type Pool struct {
...@@ -28,12 +28,20 @@ func (T *Pool) handle(req request.Request) { ...@@ -28,12 +28,20 @@ func (T *Pool) handle(req request.Request) {
default: default:
} }
} }
// choose a random sink to wait for
if len(T.sinks) == 0 { if len(T.sinks) == 0 {
// TODO(garet) this should just error // TODO(garet) this should just error
panic("no free pools") panic("no free pools")
} }
T.sinks[rand.Intn(len(T.sinks))].In() <- req // choose a random sink to wait for
ok := race.Send(func(i int) (chan<- request.Request, bool) {
if i >= len(T.sinks) {
return nil, false
}
return T.sinks[i].In(), true
}, req)
if !ok {
panic("failed to send req to pool")
}
} }
func (T *Pool) run() { func (T *Pool) run() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment