Permalink
Cannot retrieve contributors at this time
42 lines (39 sloc)
1.04 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/lodash/after.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toInteger = require('./toInteger'); | |
/** Error message constants. */ | |
var FUNC_ERROR_TEXT = 'Expected a function'; | |
/** | |
* The opposite of `_.before`; this method creates a function that invokes | |
* `func` once it's called `n` or more times. | |
* | |
* @static | |
* @memberOf _ | |
* @since 0.1.0 | |
* @category Function | |
* @param {number} n The number of calls before `func` is invoked. | |
* @param {Function} func The function to restrict. | |
* @returns {Function} Returns the new restricted function. | |
* @example | |
* | |
* var saves = ['profile', 'settings']; | |
* | |
* var done = _.after(saves.length, function() { | |
* console.log('done saving!'); | |
* }); | |
* | |
* _.forEach(saves, function(type) { | |
* asyncSave({ 'type': type, 'complete': done }); | |
* }); | |
* // => Logs 'done saving!' after the two async saves have completed. | |
*/ | |
function after(n, func) { | |
if (typeof func != 'function') { | |
throw new TypeError(FUNC_ERROR_TEXT); | |
} | |
n = toInteger(n); | |
return function() { | |
if (--n < 1) { | |
return func.apply(this, arguments); | |
} | |
}; | |
} | |
module.exports = after; |