Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: Clear interval when stopping (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorb authored and daviddias committed Jan 4, 2018
1 parent bd993dc commit 1d586c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class MulticastDNS extends EventEmitter {
this.serviceTag = options.serviceTag || '_ipfs-discovery._udp'
this.port = options.port || 5353
this.peerInfo = peerInfo
this._queryInterval = null
}

start (callback) {
Expand All @@ -24,7 +25,7 @@ class MulticastDNS extends EventEmitter {

this.mdns = mdns

query.queryLAN(this.mdns, this.serviceTag, this.interval)
this._queryInterval = query.queryLAN(this.mdns, this.serviceTag, this.interval)

mdns.on('response', (event) => {
query.gotResponse(event, this.peerInfo, this.serviceTag, (err, foundPeer) => {
Expand All @@ -47,6 +48,8 @@ class MulticastDNS extends EventEmitter {
if (!this.mdns) {
callback(new Error('MulticastDNS service had not started yet'))
} else {
clearInterval(this._queryInterval)
this._queryInterval = null
this.mdns.destroy(callback)
this.mdns = undefined
}
Expand Down
2 changes: 1 addition & 1 deletion src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const tcp = new TCP()
module.exports = {

queryLAN: function (mdns, serviceTag, interval) {
setInterval(() => {
return setInterval(() => {
mdns.query({
questions: [{
name: serviceTag,
Expand Down

0 comments on commit 1d586c3

Please sign in to comment.