diff --git a/lib/db/memdb.js b/lib/db/memdb.js index d3a4a645..64181ee7 100644 --- a/lib/db/memdb.js +++ b/lib/db/memdb.js @@ -7,7 +7,7 @@ 'use strict'; var assert = require('assert'); -var util = require('../utils/util'); +var nextTick = require('../utils/nexttick'); var RBT = require('../utils/rbt'); var DUMMY = Buffer.alloc(0); @@ -130,7 +130,7 @@ MemDB.prototype.open = function open(options, callback) { this.options = options; - util.nextTick(callback); + nextTick(callback); }; /** @@ -139,7 +139,7 @@ MemDB.prototype.open = function open(options, callback) { */ MemDB.prototype.close = function close(callback) { - util.nextTick(callback); + nextTick(callback); }; /** @@ -166,7 +166,7 @@ MemDB.prototype.get = function get(key, options, callback) { err = new Error('MEMDB_NOTFOUND: Key not found.'); err.notFound = true; err.type = 'NotFoundError'; - util.nextTick(function() { + nextTick(function() { callback(err); }); return; @@ -175,7 +175,7 @@ MemDB.prototype.get = function get(key, options, callback) { if (options.asBuffer === false) value = value.toString('utf8'); - util.nextTick(function() { + nextTick(function() { callback(null, value); }); }; @@ -196,7 +196,7 @@ MemDB.prototype.put = function put(key, value, options, callback) { this.insert(key, value); - util.nextTick(callback); + nextTick(callback); }; /** @@ -214,7 +214,7 @@ MemDB.prototype.del = function del(key, options, callback) { this.remove(key); - util.nextTick(callback); + nextTick(callback); }; /** @@ -282,7 +282,7 @@ MemDB.prototype.approximateSize = function approximateSize(start, end, callback) size += item.value.length; } - util.nextTick(function() { + nextTick(function() { callback(null, size); }); }; @@ -294,7 +294,7 @@ MemDB.prototype.approximateSize = function approximateSize(start, end, callback) */ MemDB.destroy = function destroy(location, callback) { - util.nextTick(callback); + nextTick(callback); }; /** @@ -304,7 +304,7 @@ MemDB.destroy = function destroy(location, callback) { */ MemDB.repair = function repair(location, callback) { - util.nextTick(callback); + nextTick(callback); }; /** @@ -355,7 +355,7 @@ Batch.prototype.write = function write(callback) { var i, op; if (this.written) { - util.nextTick(function() { + nextTick(function() { callback(new Error('Already written.')); }); return; @@ -371,7 +371,7 @@ Batch.prototype.write = function write(callback) { this.db.remove(op.key); break; default: - util.nextTick(function() { + nextTick(function() { callback(new Error('Bad operation: ' + op.type)); }); return; @@ -381,7 +381,7 @@ Batch.prototype.write = function write(callback) { this.ops = []; this.written = true; - util.nextTick(callback); + nextTick(callback); return this; }; @@ -474,7 +474,7 @@ Iterator.prototype.next = function(callback) { var key, value, result; if (!this.iter) { - util.nextTick(function() { + nextTick(function() { callback(new Error('Cannot call next after end.')); }); return; @@ -510,14 +510,14 @@ Iterator.prototype.next = function(callback) { if (!result) { this.iter = null; - util.nextTick(callback); + nextTick(callback); return; } if (options.limit !== -1) { if (this.total >= options.limit) { this.iter = null; - util.nextTick(callback); + nextTick(callback); return; } this.total += 1; @@ -538,7 +538,7 @@ Iterator.prototype.next = function(callback) { if (!options.valueAsBuffer) value = value.toString('utf8'); - util.nextTick(function() { + nextTick(function() { callback(null, key, value); }); }; @@ -569,7 +569,7 @@ Iterator.prototype.seek = function seek(key) { Iterator.prototype.end = function end(callback) { if (this.ended) { - util.nextTick(function() { + nextTick(function() { callback(new Error('Already ended.')); }); return; @@ -578,7 +578,7 @@ Iterator.prototype.end = function end(callback) { this.ended = true; this.iter = null; - util.nextTick(callback); + nextTick(callback); }; /** diff --git a/lib/utils/util.js b/lib/utils/util.js index 7415f3c6..376c9426 100644 --- a/lib/utils/util.js +++ b/lib/utils/util.js @@ -139,15 +139,6 @@ util.isHex = function isHex(obj) { && obj.length % 2 === 0; }; -/** - * Call `setImmediate`, `process.nextTick`, - * or `setInterval` depending. - * @function - * @returns {Promise} - */ - -util.nextTick = require('./nexttick'); - /** * Reverse a hex-string (used because of * bitcoind's affinity for uint256le). diff --git a/lib/workers/master.js b/lib/workers/master.js index 4792ea88..a721ef0f 100644 --- a/lib/workers/master.js +++ b/lib/workers/master.js @@ -10,6 +10,7 @@ var assert = require('assert'); var EventEmitter = require('events').EventEmitter; var util = require('../utils/util'); +var nextTick = require('../utils/nexttick'); var Network = require('../protocol/network'); var jobs = require('./jobs'); var Parser = require('./parser-client'); @@ -117,7 +118,7 @@ Master.prototype._initChildProcess = function _initChildProcess() { process.on('uncaughtException', function(err) { self.send(new packets.ErrorPacket(err)); - util.nextTick(function() { + nextTick(function() { process.exit(1); }); }); diff --git a/lib/workers/workerpool.js b/lib/workers/workerpool.js index 6f81b10b..a443db9f 100644 --- a/lib/workers/workerpool.js +++ b/lib/workers/workerpool.js @@ -12,6 +12,7 @@ var EventEmitter = require('events').EventEmitter; var os = require('os'); var cp = require('child_process'); var util = require('../utils/util'); +var nextTick = require('../utils/nexttick'); var co = require('../utils/co'); var Network = require('../protocol/network'); var jobs = require('./jobs'); @@ -272,7 +273,7 @@ WorkerPool.prototype.execute = function execute(packet, timeout) { if (!this.enabled || !WorkerPool.support) { return new Promise(function(resolve, reject) { - util.nextTick(function() { + nextTick(function() { try { result = jobs._execute(packet); } catch (e) {