From 719222b61dd05459db44147dd94d860cdf8ecd04 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 9 Aug 2016 12:34:15 -0700 Subject: [PATCH] miner: fix miner.stop(). --- lib/bcoin/miner.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/bcoin/miner.js b/lib/bcoin/miner.js index e62a9bce..d877147c 100644 --- a/lib/bcoin/miner.js +++ b/lib/bcoin/miner.js @@ -178,6 +178,8 @@ Miner.prototype.start = function start(version) { attempt.mineAsync(function(err, block) { if (err) { + if (!self.running) + return; self.emit('error', err); return self.start(); } @@ -363,6 +365,8 @@ function MinerBlock(options) { this.witness = options.witness; this.address = options.address; this.network = bcoin.network.get(options.network); + this.timeout = null; + this.callback = null; this.coinbase = new bcoin.tx(); this.coinbase.mutable = true; @@ -673,6 +677,10 @@ MinerBlock.prototype.mineAsync = function mine(callback) { if (!this.workerPool) return this.mine(callback); + callback = utils.once(callback); + + this.callback = callback; + function done(err, block) { self.workerPool.destroy(); callback(err, block); @@ -697,6 +705,10 @@ MinerBlock.prototype.destroy = function destroy() { clearTimeout(this.timeout); this.timeout = null; } + if (this.callback) { + this.callback(new Error('Destroyed.')); + this.callback = null; + } this.block = null; };