Skip to content
Closed
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var http = require('http');
var https = require('https');
var async = require('async');

function RpcClient(opts) {
opts = opts || {};
Expand All @@ -12,6 +13,7 @@ function RpcClient(opts) {
this.protocol = opts.protocol === 'http' ? http : https;
this.batchedCalls = null;
this.disableAgent = opts.disableAgent || false;
var queueSize = opts.queue || 16;

var isRejectUnauthorized = typeof opts.rejectUnauthorized !== 'undefined';
this.rejectUnauthorized = isRejectUnauthorized ? opts.rejectUnauthorized : true;
Expand All @@ -22,6 +24,9 @@ function RpcClient(opts) {
this.log = RpcClient.loggers[RpcClient.config.logger || 'normal'];
}

this.queue = async.queue(function(task, callback) {
task(callback);
}, queueSize);
}

var cl = console.log.bind(console);
Expand All @@ -40,6 +45,21 @@ RpcClient.config = {

function rpc(request, callback) {

var self = this;

var task = function(taskCallback) {
var newCallback = function() {
callback.apply(undefined, arguments);
taskCallback();
};
innerRpc.call(self, request, newCallback);
};

this.queue.push(task);
}

function innerRpc(request, callback) {

var self = this;
request = JSON.stringify(request);
var auth = new Buffer(self.user + ':' + self.pass).toString('base64');
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
"coverage": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- --recursive"
},
"devDependencies": {
"async": "^0.9.0",
"chai": "^1.10.0",
"coveralls": "^2.11.2",
"istanbul": "^0.3.5",
"mocha": "^2.1.0",
"sinon": "^1.12.2"
},
"dependencies": {
"async": "^1.3.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest use fixed deps or yarn. This right here will lead to undeterministic builds and heavy pain in the future. Async is a well maintained library, that is for sure but still they can f**k up a release. Better be safe than sorry.

So for the time being I would make the line so:

"async":"1.3.0"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bitcore-node uses exactly this dependency, "async": "^1.3.0". Given that this is used only in bitcore-node, it doesn't matter really

},
"bugs": {
"url": "https://github.com/bitpay/bitcoind-rpc/issues"
},
Expand Down