constant.js 2.9 KB

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