Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Commit 0fc53dd

Browse files
author
Alan Shaw
committed
fix: a better revert
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 0fb76db commit 0fc53dd

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/limit-dialer/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,25 @@ class LimitDialer {
3838
// we use a token to track if we want to cancel following dials
3939
const token = { cancel: false }
4040

41+
let errors = []
4142
const tasks = addrs.map((m) => {
42-
return (cb) => this.dialSingle(peer, transport, m, token, cb)
43+
return (cb) => this.dialSingle(peer, transport, m, token, (err, result) => {
44+
if (err) {
45+
errors.push(err)
46+
return cb(err)
47+
}
48+
return cb(null, result)
49+
})
4350
})
4451

45-
tryEach(tasks, (err, res) => {
46-
if (err) {
47-
log('dialMany:error', err)
48-
return callback(err)
52+
tryEach(tasks, (_, result) => {
53+
if (result && result.conn) {
54+
log('dialMany:success')
55+
return callback(null, result)
4956
}
50-
log('dialMany:success')
51-
callback(null, res)
57+
58+
log('dialMany:error')
59+
callback(errors)
5260
})
5361
}
5462

test/limit-dialer.node.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ describe('LimitDialer', () => {
5353
it('two success', (done) => {
5454
const dialer = new LimitDialer(2, 10)
5555

56-
expect(2).checks(done)
57-
5856
// mock transport
5957
const t1 = {
6058
dial (addr, cb) {
@@ -72,10 +70,7 @@ describe('LimitDialer', () => {
7270
setTimeout(cb, 8)
7371
return {
7472
source: pull.values([2]),
75-
sink: pull.onEnd((err) => {
76-
// Verify the unused connection gets closed
77-
expect(err).to.not.exist().mark()
78-
})
73+
sink: pull.drain()
7974
}
8075
}
8176
}
@@ -89,7 +84,8 @@ describe('LimitDialer', () => {
8984
conn,
9085
pull.collect((err, res) => {
9186
expect(err).to.not.exist()
92-
expect(res).to.be.eql([1]).mark()
87+
expect(res).to.be.eql([1])
88+
done()
9389
})
9490
)
9591
})

0 commit comments

Comments
 (0)