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

Generate index.js from a template #1483

Merged
merged 3 commits into from Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions Makefile
Expand Up @@ -13,9 +13,10 @@ XYZ = support/xyz.sh --repo git@github.com:caolan/async.git
BUILDDIR = build
BUILD_ES = build-es
DIST = dist
SRC = lib/index.js
JS_INDEX = lib/index.js
SCRIPTS = ./support
JS_SRC = $(shell find lib/ -type f -name '*.js')
JS_SRC = $(shell find lib/ -type f -name '*.js') lib/index.js
INDEX_SRC = $(shell find lib/ -type f -name '*.js' | grep -v 'index') $(SCRIPTS)/index-template.js $(SCRIPTS)/aliases.json ${SCRIPTS}/generate-index.js
LINT_FILES = lib/ mocha_test/ $(shell find perf/ -maxdepth 2 -type f) $(shell find support/ -maxdepth 2 -type f -name "*.js") karma.conf.js

UMD_BUNDLE = $(BUILDDIR)/dist/async.js
Expand All @@ -34,6 +35,7 @@ clean:
rm -rf $(BUILDDIR)
rm -rf $(BUILD_ES)
rm -rf $(DIST)
rm -rf $(JS_INDEX)
rm -rf tmp/ docs/ .nyc_output/ coverage/
rm -rf perf/versions/

Expand All @@ -45,6 +47,9 @@ build-bundle: build-modules $(UMD_BUNDLE)

build-modules: $(CJS_MODULES)

$(JS_INDEX): $(INDEX_SRC)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be added as a dependency of build-dist?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it already is, sorry.

node $(SCRIPTS)/generate-index.js > $@

$(BUILDDIR)/%.js: lib/%.js
mkdir -p "$(@D)"
node $(SCRIPTS)/build/compile-module.js --file $< --output $@
Expand Down
215 changes: 116 additions & 99 deletions dist/async.js
Expand Up @@ -14,6 +14,59 @@ function slice(arrayLike, start) {
return newArr;
}

/**
* Creates a continuation function with some arguments already applied.
*
* Useful as a shorthand when combined with other control flow functions. Any
* arguments passed to the returned function are added to the arguments
* originally passed to apply.
*
* @name apply
* @static
* @memberOf module:Utils
* @method
* @category Util
* @param {Function} fn - The function you want to eventually apply all
* arguments to. Invokes with (arguments...).
* @param {...*} arguments... - Any number of arguments to automatically apply
* when the continuation is called.
* @returns {Function} the partially-applied function
* @example
*
* // using apply
* async.parallel([
* async.apply(fs.writeFile, 'testfile1', 'test1'),
* async.apply(fs.writeFile, 'testfile2', 'test2')
* ]);
*
*
* // the same process without using apply
* async.parallel([
* function(callback) {
* fs.writeFile('testfile1', 'test1', callback);
* },
* function(callback) {
* fs.writeFile('testfile2', 'test2', callback);
* }
* ]);
*
* // It's possible to pass any number of additional arguments when calling the
* // continuation:
*
* node> var fn = async.apply(sys.puts, 'one');
* node> fn('two', 'three');
* one
* two
* three
*/
var apply = function(fn/*, ...args*/) {
var args = slice(arguments, 1);
return function(/*callArgs*/) {
var callArgs = slice(arguments);
return fn.apply(null, args.concat(callArgs));
};
};

var initialParams = function (fn) {
return function (/*...args, callback*/) {
var args = slice(arguments);
Expand Down Expand Up @@ -1216,59 +1269,6 @@ var mapSeries = doLimit(mapLimit, 1);
*/
var applyEachSeries = applyEach$1(mapSeries);

/**
* Creates a continuation function with some arguments already applied.
*
* Useful as a shorthand when combined with other control flow functions. Any
* arguments passed to the returned function are added to the arguments
* originally passed to apply.
*
* @name apply
* @static
* @memberOf module:Utils
* @method
* @category Util
* @param {Function} fn - The function you want to eventually apply all
* arguments to. Invokes with (arguments...).
* @param {...*} arguments... - Any number of arguments to automatically apply
* when the continuation is called.
* @returns {Function} the partially-applied function
* @example
*
* // using apply
* async.parallel([
* async.apply(fs.writeFile, 'testfile1', 'test1'),
* async.apply(fs.writeFile, 'testfile2', 'test2')
* ]);
*
*
* // the same process without using apply
* async.parallel([
* function(callback) {
* fs.writeFile('testfile1', 'test1', callback);
* },
* function(callback) {
* fs.writeFile('testfile2', 'test2', callback);
* }
* ]);
*
* // It's possible to pass any number of additional arguments when calling the
* // continuation:
*
* node> var fn = async.apply(sys.puts, 'one');
* node> fn('two', 'three');
* one
* two
* three
*/
var apply = function(fn/*, ...args*/) {
var args = slice(arguments, 1);
return function(/*callArgs*/) {
var callArgs = slice(arguments);
return fn.apply(null, args.concat(callArgs));
};
};

/**
* A specialized version of `_.forEach` for arrays without support for
* iteratee shorthands.
Expand Down Expand Up @@ -2199,6 +2199,7 @@ function queue(worker, concurrency, payload) {
var numRunning = 0;
var workersList = [];

var processingScheduled = false;
function _insert(data, insertAtFront, callback) {
if (callback != null && typeof callback !== 'function') {
throw new Error('task callback must be a function');
Expand Down Expand Up @@ -2226,7 +2227,14 @@ function queue(worker, concurrency, payload) {
q._tasks.push(item);
}
}
setImmediate$1(q.process);

if (!processingScheduled) {
processingScheduled = true;
setImmediate$1(function() {
processingScheduled = false;
q.process();
});
}
}

function _next(tasks) {
Expand All @@ -2237,7 +2245,9 @@ function queue(worker, concurrency, payload) {
var task = tasks[i];

var index = baseIndexOf(workersList, task, 0);
if (index >= 0) {
if (index === 0) {
workersList.shift();
} else if (index > 0) {
workersList.splice(index, 1);
}

Expand Down Expand Up @@ -3804,7 +3814,7 @@ function memoize(fn, hasher) {

/**
* Calls `callback` on a later loop around the event loop. In Node.js this just
* calls `setImmediate`. In the browser it will use `setImmediate` if
* calls `process.nextTicl`. In the browser it will use `setImmediate` if
* available, otherwise `setTimeout(callback, 0)`, which means other higher
* priority events may precede the execution of `callback`.
*
Expand All @@ -3814,7 +3824,7 @@ function memoize(fn, hasher) {
* @static
* @memberOf module:Utils
* @method
* @alias setImmediate
* @see [async.setImmediate]{@link module:Utils.setImmediate}
* @category Util
* @param {Function} callback - The function to call on a later loop around
* the event loop. Invoked with (args...).
Expand Down Expand Up @@ -4274,43 +4284,6 @@ function reflect(fn) {
});
}

function reject$1(eachfn, arr, iteratee, callback) {
_filter(eachfn, arr, function(value, cb) {
iteratee(value, function(err, v) {
cb(err, !v);
});
}, callback);
}

/**
* The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
*
* @name reject
* @static
* @memberOf module:Collections
* @method
* @see [async.filter]{@link module:Collections.filter}
* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Function} iteratee - An async truth test to apply to each item in
* `coll`.
* The should complete with a boolean value as its `result`.
* Invoked with (item, callback).
* @param {Function} [callback] - A callback which is called after all the
* `iteratee` functions have finished. Invoked with (err, results).
* @example
*
* async.reject(['file1','file2','file3'], function(filePath, callback) {
* fs.access(filePath, function(err) {
* callback(null, !err)
* });
* }, function(err, results) {
* // results now equals an array of missing files
* createFiles(results);
* });
*/
var reject = doParallel(reject$1);

/**
* A helper function that wraps an array or an object of functions with `reflect`.
*
Expand Down Expand Up @@ -4391,6 +4364,43 @@ function reflectAll(tasks) {
return results;
}

function reject$1(eachfn, arr, iteratee, callback) {
_filter(eachfn, arr, function(value, cb) {
iteratee(value, function(err, v) {
cb(err, !v);
});
}, callback);
}

/**
* The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
*
* @name reject
* @static
* @memberOf module:Collections
* @method
* @see [async.filter]{@link module:Collections.filter}
* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Function} iteratee - An async truth test to apply to each item in
* `coll`.
* The should complete with a boolean value as its `result`.
* Invoked with (item, callback).
* @param {Function} [callback] - A callback which is called after all the
* `iteratee` functions have finished. Invoked with (err, results).
* @example
*
* async.reject(['file1','file2','file3'], function(filePath, callback) {
* fs.access(filePath, function(err) {
* callback(null, !err)
* });
* }, function(err, results) {
* // results now equals an array of missing files
* createFiles(results);
* });
*/
var reject = doParallel(reject$1);

/**
* The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a
* time.
Expand Down Expand Up @@ -4530,8 +4540,8 @@ function constant$1(value) {
* // do something with the result
* });
*
* // It can also be embedded within other control flow functions to retry
* // individual methods that are not as reliable, like this:
* // to retry individual methods that are not as reliable within other
* // control flow functions, use the `retryable` wrapper:
* async.auto({
* users: api.getUsers.bind(api),
* payments: async.retryable(3, api.getPayments.bind(api))
Expand Down Expand Up @@ -5098,7 +5108,7 @@ function transform (coll, accumulator, iteratee, callback) {
* `result` arguments of the last attempt at completing the `task`. Invoked with
* (err, results).
* @example
* async.try([
* async.tryEach([
* function getDataFromFirstWebsite(callback) {
* // Try getting the data from the first website
* callback(err, data);
Expand Down Expand Up @@ -5373,9 +5383,9 @@ var waterfall = function(tasks, callback) {
*/

var index = {
apply: apply,
applyEach: applyEach,
applyEachSeries: applyEachSeries,
apply: apply,
asyncify: asyncify,
auto: auto,
autoInject: autoInject,
Expand Down Expand Up @@ -5453,7 +5463,14 @@ var index = {

// aliases
all: every,
allLimit: everyLimit,
allSeries: everySeries,
any: some,
anyLimit: someLimit,
anySeries: someSeries,
find: detect,
findLimit: detectLimit,
findSeries: detectSeries,
forEach: eachLimit,
forEachSeries: eachSeries,
forEachLimit: eachLimit$1,
Expand All @@ -5470,9 +5487,9 @@ var index = {
};

exports['default'] = index;
exports.apply = apply;
exports.applyEach = applyEach;
exports.applyEachSeries = applyEachSeries;
exports.apply = apply;
exports.asyncify = asyncify;
exports.auto = auto;
exports.autoInject = autoInject;
Expand Down
2 changes: 1 addition & 1 deletion dist/async.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/async.min.map

Large diffs are not rendered by default.