Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dynamic arguments in async.constant (ref. #1016) #1052

Merged
merged 1 commit into from
Mar 8, 2016
Merged
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
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();
});
});

});