Skip to content

Commit

Permalink
Support dynamic arguments in async.constant (ref. caolan#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfranzoia committed Mar 8, 2016
1 parent 07208a6 commit ff06a82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import rest from 'lodash/rest';

export default rest(function(values) {
var args = [null].concat(values);
return function (cb) {
return cb.apply(this, args);
return function () {
var callback = [].slice.call(arguments).pop();
return callback.apply(this, args);
};
});
28 changes: 28 additions & 0 deletions mocha_test/constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var async = require('../lib');
var expect = require('chai').expect;

describe('constant', function () {

it('basic usage', function(done){
var f = async.constant(42, 1, 2, 3);
f(function (err, value, a, b, c) {
expect(err).to.equal(null);
expect(value).to.equal(42);
expect(a).to.equal(1);
expect(b).to.equal(2);
expect(c).to.equal(3);
done();
});
});

it('called with multiple arguments', function(done){
var f = async.constant(42, 1, 2, 3);
f('argument to ignore', 'another argument', function (err, value, a) {
expect(err).to.equal(null);
expect(value).to.equal(42);
expect(a).to.equal(1);
done();
});
});

});

0 comments on commit ff06a82

Please sign in to comment.