Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit b295fcd

Browse files
committed
feat: implement softFail option
1 parent 693df7b commit b295fcd

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ function getServerForAddress (addr) {
2525
* @param {PeerId} options.id - Id for the crypto challenge
2626
* @param {Transport[]} options.transports - Transport(s) for microswitch
2727
* @param {Muxer[]} options.muxers - Muxer(s) for microswitch
28+
* @param {boolean} options.softFail - Whether to softly fail on listen errors
2829
*/
2930
class Stardust {
30-
constructor ({ transports, muxers, id }) {
31+
constructor ({ transports, muxers, id, softFail }) {
3132
this.switch = new MicroSwitch({ transports, addresses: [], muxers })
3233
this.id = id
34+
this.softFail = softFail
3335

3436
this.discovery = new EE()
3537
this.discovery.tag = 'stardust'

src/listener.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ class Listener extends EventEmitter {
4040
this.emit('listening')
4141
callback()
4242
}, err => {
43-
this.emit('error', err)
44-
callback(err)
43+
if (this.client.softFail) {
44+
this.emit('listening')
45+
callback()
46+
// dials will fail, but that's just about it
47+
} else {
48+
this.emit('error', err)
49+
callback(err)
50+
}
4551
})
4652
}
4753

0 commit comments

Comments
 (0)