miner: fix miner.stop().

This commit is contained in:
Christopher Jeffrey 2016-08-09 12:34:15 -07:00
parent 6ee7ac8a51
commit 719222b61d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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;
};