diff --git a/lib/scheduler.js b/lib/scheduler.js index 3ed4b8f..a3aa2d9 100644 --- a/lib/scheduler.js +++ b/lib/scheduler.js @@ -22,6 +22,8 @@ class Scheduler { #peer /** @type {Connections} */ #connections + /** @type {boolean} */ + #closed /** * @param {Peer} peer @@ -30,15 +32,18 @@ class Scheduler { constructor(peer, connections) { this.#peer = peer this.#connections = connections + this.#closed = true } /** * @param {Multiaddr} multiaddr */ async #scheduleWithHub(multiaddr) { - /** @type {[Error, null] | [null, any]} */ - const [err, hubRPC] = await run(this.#connections.connect)(multiaddr) - if (err) { + /**@type {any}*/ + let hubRPC + try { + hubRPC = await this.#connections.connect(multiaddr) + } catch (err) { debug('Failed to connect to hub at "%s" because %o', multiaddr, err) return } @@ -73,13 +78,13 @@ class Scheduler { } start() { - if (!this.closed) return - this.closed = false - + if (!this.#closed) return + this.#closed = false this.#setupHubDiscovery(); } stop() { + this.#closed = true // FIXME: implement } }