Skip to content

Commit d6bf57e

Browse files
authored
Merge pull request #3 from gillesdemey/master
Re-emit swim errors
2 parents 874ab98 + d79bf6a commit d6bf57e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Events:
6363
to another peer, relevant keys `start`, `end`, `to`.
6464
* `'steal'`: when a part of the hashring is stolen by the current peer
6565
from another peer, relevant keys `start`, `end`, `from`.
66+
* `'error'`: when an error occurs in the [`swim`](https://github.com/mcollina/baseswim) instance.
6667

6768
<a name="lookup"></a>
6869
### instance.lookup(key)

hashring.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ function Hashring (opts) {
6666
this._remove(meta)
6767
this.emit('peerDown', meta)
6868
})
69+
this.swim.on('error', err => {
70+
this.emit('error', err)
71+
})
6972
}
7073

7174
inherits(Hashring, EE)

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ test('move event', { timeout: 5000 }, (t) => {
156156
})
157157
})
158158

159+
test('error event', (t) => {
160+
t.plan(2)
161+
162+
const peer = hashring({
163+
joinTimeout: 10,
164+
base: ['0.0.0.0:7799']
165+
})
166+
.on('error', err => {
167+
t.ok(err instanceof Error)
168+
t.equal(err.name, 'JoinFailedError')
169+
peer.close()
170+
})
171+
})
172+
159173
test('client', (t) => {
160174
t.plan(4)
161175

0 commit comments

Comments
 (0)