Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 30, 2012
Garrett Johnson Clean up argument handling
Closes #79.
34a5d69
Commits on Dec 31, 2012
@tj Merge pull request #80 from gjohnson/master
Clean up message arguments
8f47de7
View
19 lib/plugins/round-robin.js
@@ -1,5 +1,11 @@
/**
+ * Deps.
+ */
+
+var slice = require('../utils').slice;
+
+/**
* Round-robin plugin.
*
* Provides a `send` method which will
@@ -34,19 +40,12 @@ module.exports = function(options){
sock.send = function(msg){
var socks = this.socks
, len = socks.length
- , sock = socks[n++ % len]
- , args = [];
+ , sock = socks[n++ % len];
- if (Array.isArray(msg)) {
- args = msg;
- } else {
- for (var i = 0; i < arguments.length; ++i) {
- args[i] = arguments[i];
- }
- }
+ if (arguments.length > 1) msg = slice(arguments);
if (sock && sock.writable) {
- sock.write(this.pack(args));
+ sock.write(this.pack(msg));
} else {
fallback(msg);
}
View
14 lib/sockets/pub.js
@@ -4,7 +4,8 @@
*/
var Socket = require('./sock')
- , Batch = require('../batch');
+ , Batch = require('../batch')
+ , slice = require('../utils').slice;
/**
* Expose `PubSocket`.
@@ -73,15 +74,8 @@ PubSocket.prototype.flushBatch = function(){
PubSocket.prototype.send = function(msg){
if (++this.n == this.get('batch max')) return this.flushBatch();
- if (Array.isArray(msg)) {
- this.batch.add(this.pack(msg));
- } else {
- var args = [];
- for (var i = 0; i < arguments.length; ++i) {
- args[i] = arguments[i];
- }
- this.batch.add(this.pack(args));
- }
+ if (arguments.length > 1) msg = slice(arguments);
+ this.batch.add(this.pack(msg));
return this;
};
View
13 lib/sockets/req.js
@@ -5,6 +5,7 @@
var Socket = require('./sock')
, queue = require('../plugins/queue')
+ , slice = require('../utils').slice
, debug = require('debug')('axon:req');
/**
@@ -78,15 +79,9 @@ ReqSocket.prototype.send = function(msg){
var socks = this.socks
, len = socks.length
, sock = socks[this.n++ % len]
- , args = [];
-
- if (Array.isArray(msg)) {
- args = msg;
- } else {
- for (var i = 0; i < arguments.length; ++i) {
- args[i] = arguments[i];
- }
- }
+ , args = Array.isArray(msg)
+ ? msg
+ : slice(arguments);
if (sock) {
if ('function' == typeof args[args.length - 1]) {
View
19 lib/utils.js
@@ -0,0 +1,19 @@
+
+/**
+ * Slice helper.
+ *
+ * @api private
+ * @param {Arguments} args
+ * @return {Array}
+ */
+
+exports.slice = function(args){
+ var len = args.length
+ , ret = new Array(len);
+
+ for (var i = 0; i < len; i++) {
+ ret[i] = args[i];
+ }
+
+ return ret;
+};

No commit comments for this range

Something went wrong with that request. Please try again.