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

fix: match libp2p/interface-peer-discovery spec #141

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/random-walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const assert = require('assert')
const AbortController = require('abort-controller')
const errcode = require('err-code')
const times = require('p-times')
const setImmediate = require('async/setImmediate')
const c = require('./constants')
const { logger } = require('./utils')

Expand Down Expand Up @@ -36,9 +37,10 @@ class RandomWalk {
* every interval requesting random data. This is done to keep the dht
* healthy over time.
*
* @param {function()} callback
* @returns {void}
*/
start () {
start (callback) {
// Don't run twice
if (this._timeoutId || !this._options.enabled) { return }

Expand All @@ -47,20 +49,23 @@ class RandomWalk {
// Start runner immediately
this._runPeriodically()
}, this._options.delay)
setImmediate(callback || (() => {}))
}

/**
* Stop the random-walk process. Any active
* queries will be aborted.
*
* @param {function()} callback
* @returns {void}
*/
stop () {
stop (callback) {
if (this._timeoutId) {
clearTimeout(this._timeoutId)
this._timeoutId = undefined
}
this._controller && this._controller.abort()
setImmediate(callback || (() => {}))
}

/**
Expand Down