Skip to content

Commit

Permalink
Merge pull request #312 from libp2p/fix/dial-queue
Browse files Browse the repository at this point in the history
dialQueue: start the control loop later
  • Loading branch information
raulk authored Mar 27, 2019
2 parents 6433bf6 + 29d5b4a commit 4f397ca
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dial_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}

Expand All @@ -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.
Expand Down

0 comments on commit 4f397ca

Please sign in to comment.