mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
dialQueue: start the control loop later
Don't start the control loop till we start the queue. The _in_ queue will still work, we just won't start processing peers from it until we start the control loop. fixes #311
This commit is contained in:
parent
6433bf68f3
commit
29d5b4af70
@ -110,18 +110,13 @@ func newDialQueue(params *dqParams) (*dialQueue, error) {
|
||||
dieCh: make(chan struct{}, params.config.maxParallelism),
|
||||
}
|
||||
|
||||
go dq.control()
|
||||
return dq, nil
|
||||
}
|
||||
|
||||
// Start initiates action on this dial queue. It should only be called once; subsequent calls are ignored.
|
||||
func (dq *dialQueue) Start() {
|
||||
dq.startOnce.Do(func() {
|
||||
tgt := int(dq.dqParams.config.minParallelism)
|
||||
for i := 0; i < tgt; i++ {
|
||||
go dq.worker()
|
||||
}
|
||||
dq.nWorkers = uint(tgt)
|
||||
go dq.control()
|
||||
})
|
||||
}
|
||||
|
||||
@ -139,6 +134,16 @@ func (dq *dialQueue) control() {
|
||||
waiting = nil
|
||||
}()
|
||||
|
||||
// start workers
|
||||
|
||||
tgt := int(dq.dqParams.config.minParallelism)
|
||||
for i := 0; i < tgt; i++ {
|
||||
go dq.worker()
|
||||
}
|
||||
dq.nWorkers = uint(tgt)
|
||||
|
||||
// control workers
|
||||
|
||||
for {
|
||||
// First process any backlog of dial jobs and waiters -- making progress is the priority.
|
||||
// This block is copied below; couldn't find a more concise way of doing this.
|
||||
|
Loading…
x
Reference in New Issue
Block a user