constant.js 1.7 KB

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