constant.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _rest = require('./internal/rest');
  6. var _rest2 = _interopRequireDefault(_rest);
  7. var _initialParams = require('./internal/initialParams');
  8. var _initialParams2 = _interopRequireDefault(_initialParams);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * Returns a function that when called, calls-back with the values provided.
  12. * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to
  13. * [`auto`]{@link module:ControlFlow.auto}.
  14. *
  15. * @name constant
  16. * @static
  17. * @memberOf module:Utils
  18. * @method
  19. * @category Util
  20. * @param {...*} arguments... - Any number of arguments to automatically invoke
  21. * callback with.
  22. * @returns {Function} Returns a function that when invoked, automatically
  23. * invokes the callback with the previous given arguments.
  24. * @example
  25. *
  26. * async.waterfall([
  27. * async.constant(42),
  28. * function (value, next) {
  29. * // value === 42
  30. * },
  31. * //...
  32. * ], callback);
  33. *
  34. * async.waterfall([
  35. * async.constant(filename, "utf8"),
  36. * fs.readFile,
  37. * function (fileData, next) {
  38. * //...
  39. * }
  40. * //...
  41. * ], callback);
  42. *
  43. * async.auto({
  44. * hostname: async.constant("https://server.net/"),
  45. * port: findFreePort,
  46. * launchServer: ["hostname", "port", function (options, cb) {
  47. * startServer(options, cb);
  48. * }],
  49. * //...
  50. * }, callback);
  51. */
  52. exports.default = (0, _rest2.default)(function (values) {
  53. var args = [null].concat(values);
  54. return (0, _initialParams2.default)(function (ignoredArgs, callback) {
  55. return callback.apply(this, args);
  56. });
  57. });
  58. module.exports = exports['default'];