From 7127b67f94a22247c36bf40e4f2685912e0f80e9 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 15 Dec 2015 12:36:20 +0100 Subject: [PATCH 01/36] Initial work in progress - modularization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add .DS_Store Extract util methods Fix createTester callback Fix notid exports Refactor settimediate and nexttick Fix dep path Create bundle using browserify Rename main file Rename main file Rename main file Use browserify standalone mode Modular interface for main methods 📦 Deleted unnecessary test Add script to generate modules package.json Delete noconflict module Improve how to generat browser bundle Update util modules references Add a way to generate module scaffold Fix version Remove unnecessary dependencies Require the dependency Add missing methods Add dependencies for each module Bumped 0.4.0 Add useful scripts Add .npmignore Updated Add npmignore files Refactor Fix little issues Fix library name Fix isarray module Update script Fix typo Fix template links Update deps Revert "Fix template links" This reverts commit 112a3822f5aeab04d3ebec2e286ade10639f4668. Bump 0.5.1 Fix mapseries reference Bump 0.5.2 --- .editorconfig | 10 + .gitignore | 2 + .npmignore | 4 + Makefile | 6 +- gulpfile.js | 88 ++ lib/apply/.editorconfig | 10 + lib/apply/.gitignore | 8 + lib/apply/.jscsrc | 3 + lib/apply/.jshintrc | 29 + lib/apply/README.md | 13 + lib/apply/index.js | 9 + lib/apply/package.json | 20 + lib/applyeach/.editorconfig | 10 + lib/applyeach/.gitignore | 8 + lib/applyeach/.jscsrc | 3 + lib/applyeach/.jshintrc | 29 + lib/applyeach/README.md | 13 + lib/applyeach/index.js | 6 + lib/applyeach/package.json | 21 + lib/applyeachseries/.editorconfig | 10 + lib/applyeachseries/.gitignore | 8 + lib/applyeachseries/.jscsrc | 3 + lib/applyeachseries/.jshintrc | 29 + lib/applyeachseries/README.md | 13 + lib/applyeachseries/index.js | 6 + lib/applyeachseries/package.json | 21 + lib/async.js | 1259 ----------------------------- lib/asyncify/.editorconfig | 10 + lib/asyncify/.gitignore | 8 + lib/asyncify/.jscsrc | 3 + lib/asyncify/.jshintrc | 29 + lib/asyncify/README.md | 13 + lib/asyncify/index.js | 2 + lib/asyncify/package.json | 20 + lib/auto/.editorconfig | 10 + lib/auto/.gitignore | 8 + lib/auto/.jscsrc | 3 + lib/auto/.jshintrc | 29 + lib/auto/README.md | 13 + lib/auto/index.js | 109 +++ lib/auto/package.json | 29 + lib/cargo/.editorconfig | 10 + lib/cargo/.gitignore | 8 + lib/cargo/.jscsrc | 3 + lib/cargo/.jshintrc | 29 + lib/cargo/README.md | 13 + lib/cargo/index.js | 7 + lib/cargo/package.json | 20 + lib/compose/.editorconfig | 10 + lib/compose/.gitignore | 8 + lib/compose/.jscsrc | 3 + lib/compose/.jshintrc | 29 + lib/compose/README.md | 13 + lib/compose/index.js | 7 + lib/compose/package.json | 20 + lib/concat/.editorconfig | 10 + lib/concat/.gitignore | 8 + lib/concat/.jscsrc | 3 + lib/concat/.jshintrc | 29 + lib/concat/README.md | 13 + lib/concat/index.js | 6 + lib/concat/package.json | 21 + lib/concatseries/.editorconfig | 10 + lib/concatseries/.gitignore | 8 + lib/concatseries/.jscsrc | 3 + lib/concatseries/.jshintrc | 29 + lib/concatseries/README.md | 13 + lib/concatseries/index.js | 6 + lib/concatseries/package.json | 21 + lib/constant/.editorconfig | 10 + lib/constant/.gitignore | 8 + lib/constant/.jscsrc | 3 + lib/constant/.jshintrc | 29 + lib/constant/README.md | 13 + lib/constant/index.js | 10 + lib/constant/package.json | 20 + lib/detect/.editorconfig | 10 + lib/detect/.gitignore | 8 + lib/detect/.jscsrc | 3 + lib/detect/.jshintrc | 29 + lib/detect/README.md | 13 + lib/detect/index.js | 8 + lib/detect/package.json | 23 + lib/detectlimit/.editorconfig | 10 + lib/detectlimit/.gitignore | 8 + lib/detectlimit/.jscsrc | 3 + lib/detectlimit/.jshintrc | 29 + lib/detectlimit/README.md | 13 + lib/detectlimit/index.js | 8 + lib/detectlimit/package.json | 23 + lib/detectseries/.editorconfig | 10 + lib/detectseries/.gitignore | 8 + lib/detectseries/.jscsrc | 3 + lib/detectseries/.jshintrc | 29 + lib/detectseries/README.md | 13 + lib/detectseries/index.js | 8 + lib/detectseries/package.json | 23 + lib/dir/.editorconfig | 10 + lib/dir/.gitignore | 8 + lib/dir/.jscsrc | 3 + lib/dir/.jshintrc | 29 + lib/dir/README.md | 13 + lib/dir/index.js | 2 + lib/dir/package.json | 20 + lib/doduring/.editorconfig | 10 + lib/doduring/.gitignore | 8 + lib/doduring/.jscsrc | 3 + lib/doduring/.jshintrc | 29 + lib/doduring/README.md | 13 + lib/doduring/index.js | 12 + lib/doduring/package.json | 20 + lib/dountil/.editorconfig | 10 + lib/dountil/.gitignore | 8 + lib/dountil/.jscsrc | 3 + lib/dountil/.jshintrc | 29 + lib/dountil/README.md | 13 + lib/dountil/index.js | 9 + lib/dountil/package.json | 20 + lib/dowhilst/.editorconfig | 10 + lib/dowhilst/.gitignore | 8 + lib/dowhilst/.jscsrc | 3 + lib/dowhilst/.jshintrc | 29 + lib/dowhilst/README.md | 13 + lib/dowhilst/index.js | 10 + lib/dowhilst/package.json | 20 + lib/during/.editorconfig | 10 + lib/during/.gitignore | 8 + lib/during/.jscsrc | 3 + lib/during/.jshintrc | 29 + lib/during/README.md | 13 + lib/during/index.js | 25 + lib/during/package.json | 21 + lib/each/.editorconfig | 10 + lib/each/.gitignore | 8 + lib/each/.jscsrc | 3 + lib/each/.jshintrc | 29 + lib/each/README.md | 13 + lib/each/index.js | 8 + lib/each/package.json | 21 + lib/eachlimit/.editorconfig | 10 + lib/eachlimit/.gitignore | 8 + lib/eachlimit/.jscsrc | 3 + lib/eachlimit/.jshintrc | 29 + lib/eachlimit/README.md | 13 + lib/eachlimit/index.js | 8 + lib/eachlimit/package.json | 21 + lib/eachof/.editorconfig | 10 + lib/eachof/.gitignore | 8 + lib/eachof/.jscsrc | 3 + lib/eachof/.jshintrc | 29 + lib/eachof/README.md | 13 + lib/eachof/index.js | 33 + lib/eachof/package.json | 23 + lib/eachoflimit/.editorconfig | 10 + lib/eachoflimit/.gitignore | 8 + lib/eachoflimit/.jscsrc | 3 + lib/eachoflimit/.jshintrc | 29 + lib/eachoflimit/README.md | 13 + lib/eachoflimit/index.js | 7 + lib/eachoflimit/package.json | 20 + lib/eachofseries/.editorconfig | 10 + lib/eachofseries/.gitignore | 8 + lib/eachofseries/.jscsrc | 3 + lib/eachofseries/.jshintrc | 29 + lib/eachofseries/README.md | 13 + lib/eachofseries/index.js | 39 + lib/eachofseries/package.json | 24 + lib/eachseries/.editorconfig | 10 + lib/eachseries/.gitignore | 8 + lib/eachseries/.jscsrc | 3 + lib/eachseries/.jshintrc | 29 + lib/eachseries/README.md | 13 + lib/eachseries/index.js | 8 + lib/eachseries/package.json | 21 + lib/ensureasync/.editorconfig | 10 + lib/ensureasync/.gitignore | 8 + lib/ensureasync/.jscsrc | 3 + lib/ensureasync/.jshintrc | 29 + lib/ensureasync/README.md | 13 + lib/ensureasync/index.js | 2 + lib/ensureasync/package.json | 20 + lib/every/.editorconfig | 10 + lib/every/.gitignore | 8 + lib/every/.jscsrc | 3 + lib/every/.jshintrc | 29 + lib/every/README.md | 13 + lib/every/index.js | 7 + lib/every/package.json | 22 + lib/everylimit/.editorconfig | 10 + lib/everylimit/.gitignore | 8 + lib/everylimit/.jscsrc | 3 + lib/everylimit/.jshintrc | 29 + lib/everylimit/README.md | 13 + lib/everylimit/index.js | 7 + lib/everylimit/package.json | 22 + lib/filter/.editorconfig | 10 + lib/filter/.gitignore | 8 + lib/filter/.jscsrc | 3 + lib/filter/.jshintrc | 29 + lib/filter/README.md | 13 + lib/filter/index.js | 4 + lib/filter/package.json | 21 + lib/filterlimit/.editorconfig | 10 + lib/filterlimit/.gitignore | 8 + lib/filterlimit/.jscsrc | 3 + lib/filterlimit/.jshintrc | 29 + lib/filterlimit/README.md | 13 + lib/filterlimit/index.js | 4 + lib/filterlimit/package.json | 21 + lib/filterseries/.editorconfig | 10 + lib/filterseries/.gitignore | 8 + lib/filterseries/.jscsrc | 3 + lib/filterseries/.jshintrc | 29 + lib/filterseries/README.md | 13 + lib/filterseries/index.js | 6 + lib/filterseries/package.json | 21 + lib/forever/.editorconfig | 10 + lib/forever/.gitignore | 8 + lib/forever/.jscsrc | 3 + lib/forever/.jshintrc | 29 + lib/forever/README.md | 13 + lib/forever/index.js | 14 + lib/forever/package.json | 22 + lib/index.js | 132 +++ lib/iterator/.editorconfig | 10 + lib/iterator/.gitignore | 8 + lib/iterator/.jscsrc | 3 + lib/iterator/.jshintrc | 29 + lib/iterator/README.md | 13 + lib/iterator/index.js | 17 + lib/iterator/package.json | 17 + lib/log/.editorconfig | 10 + lib/log/.gitignore | 8 + lib/log/.jscsrc | 3 + lib/log/.jshintrc | 29 + lib/log/README.md | 13 + lib/log/index.js | 2 + lib/log/package.json | 20 + lib/map/.editorconfig | 10 + lib/map/.gitignore | 8 + lib/map/.jscsrc | 3 + lib/map/.jshintrc | 29 + lib/map/README.md | 13 + lib/map/index.js | 4 + lib/map/package.json | 21 + lib/maplimit/.editorconfig | 10 + lib/maplimit/.gitignore | 8 + lib/maplimit/.jscsrc | 3 + lib/maplimit/.jshintrc | 29 + lib/maplimit/README.md | 13 + lib/maplimit/index.js | 6 + lib/maplimit/package.json | 21 + lib/mapseries/.editorconfig | 10 + lib/mapseries/.gitignore | 8 + lib/mapseries/.jscsrc | 3 + lib/mapseries/.jshintrc | 29 + lib/mapseries/README.md | 13 + lib/mapseries/index.js | 4 + lib/mapseries/package.json | 21 + lib/memoize/.editorconfig | 10 + lib/memoize/.gitignore | 8 + lib/memoize/.jscsrc | 3 + lib/memoize/.jshintrc | 29 + lib/memoize/README.md | 13 + lib/memoize/index.js | 35 + lib/memoize/package.json | 22 + lib/nexttick/.editorconfig | 10 + lib/nexttick/.gitignore | 8 + lib/nexttick/.jscsrc | 3 + lib/nexttick/.jshintrc | 29 + lib/nexttick/README.md | 13 + lib/nexttick/index.js | 2 + lib/nexttick/package.json | 20 + lib/parallel/.editorconfig | 10 + lib/parallel/.gitignore | 8 + lib/parallel/.jscsrc | 3 + lib/parallel/.jshintrc | 29 + lib/parallel/README.md | 13 + lib/parallel/index.js | 8 + lib/parallel/package.json | 21 + lib/parallellimit/.editorconfig | 10 + lib/parallellimit/.gitignore | 8 + lib/parallellimit/.jscsrc | 3 + lib/parallellimit/.jshintrc | 29 + lib/parallellimit/README.md | 13 + lib/parallellimit/index.js | 8 + lib/parallellimit/package.json | 21 + lib/priorityqueue/.editorconfig | 10 + lib/priorityqueue/.gitignore | 8 + lib/priorityqueue/.jscsrc | 3 + lib/priorityqueue/.jshintrc | 29 + lib/priorityqueue/README.md | 13 + lib/priorityqueue/index.js | 71 ++ lib/priorityqueue/package.json | 24 + lib/queue/.editorconfig | 10 + lib/queue/.gitignore | 8 + lib/queue/.jscsrc | 3 + lib/queue/.jshintrc | 29 + lib/queue/README.md | 13 + lib/queue/index.js | 9 + lib/queue/package.json | 20 + lib/reduce/.editorconfig | 10 + lib/reduce/.gitignore | 8 + lib/reduce/.jscsrc | 3 + lib/reduce/.jshintrc | 29 + lib/reduce/README.md | 13 + lib/reduce/index.js | 14 + lib/reduce/package.json | 20 + lib/reduceright/.editorconfig | 10 + lib/reduceright/.gitignore | 8 + lib/reduceright/.jscsrc | 3 + lib/reduceright/.jshintrc | 29 + lib/reduceright/README.md | 13 + lib/reduceright/index.js | 10 + lib/reduceright/package.json | 22 + lib/reject/.editorconfig | 10 + lib/reject/.gitignore | 8 + lib/reject/.jscsrc | 3 + lib/reject/.jshintrc | 29 + lib/reject/README.md | 13 + lib/reject/index.js | 6 + lib/reject/package.json | 21 + lib/rejectlimit/.editorconfig | 10 + lib/rejectlimit/.gitignore | 8 + lib/rejectlimit/.jscsrc | 3 + lib/rejectlimit/.jshintrc | 29 + lib/rejectlimit/README.md | 13 + lib/rejectlimit/index.js | 6 + lib/rejectlimit/package.json | 21 + lib/rejectseries/.editorconfig | 10 + lib/rejectseries/.gitignore | 8 + lib/rejectseries/.jscsrc | 3 + lib/rejectseries/.jshintrc | 29 + lib/rejectseries/README.md | 13 + lib/rejectseries/index.js | 6 + lib/rejectseries/package.json | 21 + lib/retry/.editorconfig | 10 + lib/retry/.gitignore | 8 + lib/retry/.jscsrc | 3 + lib/retry/.jshintrc | 29 + lib/retry/README.md | 13 + lib/retry/index.js | 77 ++ lib/retry/package.json | 20 + lib/seq/.editorconfig | 10 + lib/seq/.gitignore | 8 + lib/seq/.jscsrc | 3 + lib/seq/.jshintrc | 29 + lib/seq/README.md | 13 + lib/seq/index.js | 26 + lib/seq/package.json | 22 + lib/series/.editorconfig | 10 + lib/series/.gitignore | 8 + lib/series/.jscsrc | 3 + lib/series/.jshintrc | 29 + lib/series/README.md | 13 + lib/series/index.js | 8 + lib/series/package.json | 21 + lib/setimmediate/.editorconfig | 10 + lib/setimmediate/.gitignore | 8 + lib/setimmediate/.jscsrc | 3 + lib/setimmediate/.jshintrc | 29 + lib/setimmediate/README.md | 13 + lib/setimmediate/index.js | 2 + lib/setimmediate/package.json | 20 + lib/some/.editorconfig | 10 + lib/some/.gitignore | 8 + lib/some/.jscsrc | 3 + lib/some/.jshintrc | 29 + lib/some/README.md | 13 + lib/some/index.js | 8 + lib/some/package.json | 23 + lib/somelimit/.editorconfig | 10 + lib/somelimit/.gitignore | 8 + lib/somelimit/.jscsrc | 3 + lib/somelimit/.jshintrc | 29 + lib/somelimit/README.md | 13 + lib/somelimit/index.js | 8 + lib/somelimit/package.json | 23 + lib/sortby/.editorconfig | 10 + lib/sortby/.gitignore | 8 + lib/sortby/.jscsrc | 3 + lib/sortby/.jshintrc | 29 + lib/sortby/README.md | 13 + lib/sortby/index.js | 23 + lib/sortby/package.json | 21 + lib/times/.editorconfig | 10 + lib/times/.gitignore | 8 + lib/times/.jscsrc | 3 + lib/times/.jshintrc | 29 + lib/times/README.md | 13 + lib/times/index.js | 6 + lib/times/package.json | 21 + lib/timeslimit/.editorconfig | 10 + lib/timeslimit/.gitignore | 8 + lib/timeslimit/.jscsrc | 3 + lib/timeslimit/.jshintrc | 29 + lib/timeslimit/README.md | 13 + lib/timeslimit/index.js | 8 + lib/timeslimit/package.json | 21 + lib/timesseries/.editorconfig | 10 + lib/timesseries/.gitignore | 8 + lib/timesseries/.jscsrc | 3 + lib/timesseries/.jshintrc | 29 + lib/timesseries/README.md | 13 + lib/timesseries/index.js | 6 + lib/timesseries/package.json | 21 + lib/transform/.editorconfig | 10 + lib/transform/.gitignore | 8 + lib/transform/.jscsrc | 3 + lib/transform/.jshintrc | 29 + lib/transform/README.md | 13 + lib/transform/index.js | 18 + lib/transform/package.json | 21 + lib/unmemoize/.editorconfig | 10 + lib/unmemoize/.gitignore | 8 + lib/unmemoize/.jscsrc | 3 + lib/unmemoize/.jshintrc | 29 + lib/unmemoize/README.md | 13 + lib/unmemoize/index.js | 7 + lib/unmemoize/package.json | 17 + lib/until/.editorconfig | 10 + lib/until/.gitignore | 8 + lib/until/.jscsrc | 3 + lib/until/.jshintrc | 29 + lib/until/README.md | 13 + lib/until/index.js | 9 + lib/until/package.json | 20 + lib/waterfall/.editorconfig | 10 + lib/waterfall/.gitignore | 8 + lib/waterfall/.jscsrc | 3 + lib/waterfall/.jshintrc | 29 + lib/waterfall/README.md | 13 + lib/waterfall/index.js | 31 + lib/waterfall/package.json | 25 + lib/whilst/.editorconfig | 10 + lib/whilst/.gitignore | 8 + lib/whilst/.jscsrc | 3 + lib/whilst/.jshintrc | 29 + lib/whilst/README.md | 13 + lib/whilst/index.js | 15 + lib/whilst/package.json | 21 + mocha_test/compose.js | 2 +- mocha_test/forever.js | 2 +- package.json | 133 ++- scripts/each-module.js | 27 + scripts/gk.js | 4 + scripts/init.js | 9 + scripts/publish.js | 4 + scripts/push.js | 8 + support/dependencies.json | 262 ++++++ support/module_template.md | 13 + test/test-async.js | 33 +- test/test.html | 2 +- 453 files changed, 6747 insertions(+), 1328 deletions(-) create mode 100644 .editorconfig create mode 100644 .npmignore create mode 100644 gulpfile.js create mode 100644 lib/apply/.editorconfig create mode 100644 lib/apply/.gitignore create mode 100644 lib/apply/.jscsrc create mode 100644 lib/apply/.jshintrc create mode 100644 lib/apply/README.md create mode 100644 lib/apply/index.js create mode 100644 lib/apply/package.json create mode 100644 lib/applyeach/.editorconfig create mode 100644 lib/applyeach/.gitignore create mode 100644 lib/applyeach/.jscsrc create mode 100644 lib/applyeach/.jshintrc create mode 100644 lib/applyeach/README.md create mode 100644 lib/applyeach/index.js create mode 100644 lib/applyeach/package.json create mode 100644 lib/applyeachseries/.editorconfig create mode 100644 lib/applyeachseries/.gitignore create mode 100644 lib/applyeachseries/.jscsrc create mode 100644 lib/applyeachseries/.jshintrc create mode 100644 lib/applyeachseries/README.md create mode 100644 lib/applyeachseries/index.js create mode 100644 lib/applyeachseries/package.json delete mode 100644 lib/async.js create mode 100644 lib/asyncify/.editorconfig create mode 100644 lib/asyncify/.gitignore create mode 100644 lib/asyncify/.jscsrc create mode 100644 lib/asyncify/.jshintrc create mode 100644 lib/asyncify/README.md create mode 100644 lib/asyncify/index.js create mode 100644 lib/asyncify/package.json create mode 100644 lib/auto/.editorconfig create mode 100644 lib/auto/.gitignore create mode 100644 lib/auto/.jscsrc create mode 100644 lib/auto/.jshintrc create mode 100644 lib/auto/README.md create mode 100644 lib/auto/index.js create mode 100644 lib/auto/package.json create mode 100644 lib/cargo/.editorconfig create mode 100644 lib/cargo/.gitignore create mode 100644 lib/cargo/.jscsrc create mode 100644 lib/cargo/.jshintrc create mode 100644 lib/cargo/README.md create mode 100644 lib/cargo/index.js create mode 100644 lib/cargo/package.json create mode 100644 lib/compose/.editorconfig create mode 100644 lib/compose/.gitignore create mode 100644 lib/compose/.jscsrc create mode 100644 lib/compose/.jshintrc create mode 100644 lib/compose/README.md create mode 100644 lib/compose/index.js create mode 100644 lib/compose/package.json create mode 100644 lib/concat/.editorconfig create mode 100644 lib/concat/.gitignore create mode 100644 lib/concat/.jscsrc create mode 100644 lib/concat/.jshintrc create mode 100644 lib/concat/README.md create mode 100644 lib/concat/index.js create mode 100644 lib/concat/package.json create mode 100644 lib/concatseries/.editorconfig create mode 100644 lib/concatseries/.gitignore create mode 100644 lib/concatseries/.jscsrc create mode 100644 lib/concatseries/.jshintrc create mode 100644 lib/concatseries/README.md create mode 100644 lib/concatseries/index.js create mode 100644 lib/concatseries/package.json create mode 100644 lib/constant/.editorconfig create mode 100644 lib/constant/.gitignore create mode 100644 lib/constant/.jscsrc create mode 100644 lib/constant/.jshintrc create mode 100644 lib/constant/README.md create mode 100644 lib/constant/index.js create mode 100644 lib/constant/package.json create mode 100644 lib/detect/.editorconfig create mode 100644 lib/detect/.gitignore create mode 100644 lib/detect/.jscsrc create mode 100644 lib/detect/.jshintrc create mode 100644 lib/detect/README.md create mode 100644 lib/detect/index.js create mode 100644 lib/detect/package.json create mode 100644 lib/detectlimit/.editorconfig create mode 100644 lib/detectlimit/.gitignore create mode 100644 lib/detectlimit/.jscsrc create mode 100644 lib/detectlimit/.jshintrc create mode 100644 lib/detectlimit/README.md create mode 100644 lib/detectlimit/index.js create mode 100644 lib/detectlimit/package.json create mode 100644 lib/detectseries/.editorconfig create mode 100644 lib/detectseries/.gitignore create mode 100644 lib/detectseries/.jscsrc create mode 100644 lib/detectseries/.jshintrc create mode 100644 lib/detectseries/README.md create mode 100644 lib/detectseries/index.js create mode 100644 lib/detectseries/package.json create mode 100644 lib/dir/.editorconfig create mode 100644 lib/dir/.gitignore create mode 100644 lib/dir/.jscsrc create mode 100644 lib/dir/.jshintrc create mode 100644 lib/dir/README.md create mode 100644 lib/dir/index.js create mode 100644 lib/dir/package.json create mode 100644 lib/doduring/.editorconfig create mode 100644 lib/doduring/.gitignore create mode 100644 lib/doduring/.jscsrc create mode 100644 lib/doduring/.jshintrc create mode 100644 lib/doduring/README.md create mode 100644 lib/doduring/index.js create mode 100644 lib/doduring/package.json create mode 100644 lib/dountil/.editorconfig create mode 100644 lib/dountil/.gitignore create mode 100644 lib/dountil/.jscsrc create mode 100644 lib/dountil/.jshintrc create mode 100644 lib/dountil/README.md create mode 100644 lib/dountil/index.js create mode 100644 lib/dountil/package.json create mode 100644 lib/dowhilst/.editorconfig create mode 100644 lib/dowhilst/.gitignore create mode 100644 lib/dowhilst/.jscsrc create mode 100644 lib/dowhilst/.jshintrc create mode 100644 lib/dowhilst/README.md create mode 100644 lib/dowhilst/index.js create mode 100644 lib/dowhilst/package.json create mode 100644 lib/during/.editorconfig create mode 100644 lib/during/.gitignore create mode 100644 lib/during/.jscsrc create mode 100644 lib/during/.jshintrc create mode 100644 lib/during/README.md create mode 100644 lib/during/index.js create mode 100644 lib/during/package.json create mode 100644 lib/each/.editorconfig create mode 100644 lib/each/.gitignore create mode 100644 lib/each/.jscsrc create mode 100644 lib/each/.jshintrc create mode 100644 lib/each/README.md create mode 100644 lib/each/index.js create mode 100644 lib/each/package.json create mode 100644 lib/eachlimit/.editorconfig create mode 100644 lib/eachlimit/.gitignore create mode 100644 lib/eachlimit/.jscsrc create mode 100644 lib/eachlimit/.jshintrc create mode 100644 lib/eachlimit/README.md create mode 100644 lib/eachlimit/index.js create mode 100644 lib/eachlimit/package.json create mode 100644 lib/eachof/.editorconfig create mode 100644 lib/eachof/.gitignore create mode 100644 lib/eachof/.jscsrc create mode 100644 lib/eachof/.jshintrc create mode 100644 lib/eachof/README.md create mode 100644 lib/eachof/index.js create mode 100644 lib/eachof/package.json create mode 100644 lib/eachoflimit/.editorconfig create mode 100644 lib/eachoflimit/.gitignore create mode 100644 lib/eachoflimit/.jscsrc create mode 100644 lib/eachoflimit/.jshintrc create mode 100644 lib/eachoflimit/README.md create mode 100644 lib/eachoflimit/index.js create mode 100644 lib/eachoflimit/package.json create mode 100644 lib/eachofseries/.editorconfig create mode 100644 lib/eachofseries/.gitignore create mode 100644 lib/eachofseries/.jscsrc create mode 100644 lib/eachofseries/.jshintrc create mode 100644 lib/eachofseries/README.md create mode 100644 lib/eachofseries/index.js create mode 100644 lib/eachofseries/package.json create mode 100644 lib/eachseries/.editorconfig create mode 100644 lib/eachseries/.gitignore create mode 100644 lib/eachseries/.jscsrc create mode 100644 lib/eachseries/.jshintrc create mode 100644 lib/eachseries/README.md create mode 100644 lib/eachseries/index.js create mode 100644 lib/eachseries/package.json create mode 100644 lib/ensureasync/.editorconfig create mode 100644 lib/ensureasync/.gitignore create mode 100644 lib/ensureasync/.jscsrc create mode 100644 lib/ensureasync/.jshintrc create mode 100644 lib/ensureasync/README.md create mode 100644 lib/ensureasync/index.js create mode 100644 lib/ensureasync/package.json create mode 100644 lib/every/.editorconfig create mode 100644 lib/every/.gitignore create mode 100644 lib/every/.jscsrc create mode 100644 lib/every/.jshintrc create mode 100644 lib/every/README.md create mode 100644 lib/every/index.js create mode 100644 lib/every/package.json create mode 100644 lib/everylimit/.editorconfig create mode 100644 lib/everylimit/.gitignore create mode 100644 lib/everylimit/.jscsrc create mode 100644 lib/everylimit/.jshintrc create mode 100644 lib/everylimit/README.md create mode 100644 lib/everylimit/index.js create mode 100644 lib/everylimit/package.json create mode 100644 lib/filter/.editorconfig create mode 100644 lib/filter/.gitignore create mode 100644 lib/filter/.jscsrc create mode 100644 lib/filter/.jshintrc create mode 100644 lib/filter/README.md create mode 100644 lib/filter/index.js create mode 100644 lib/filter/package.json create mode 100644 lib/filterlimit/.editorconfig create mode 100644 lib/filterlimit/.gitignore create mode 100644 lib/filterlimit/.jscsrc create mode 100644 lib/filterlimit/.jshintrc create mode 100644 lib/filterlimit/README.md create mode 100644 lib/filterlimit/index.js create mode 100644 lib/filterlimit/package.json create mode 100644 lib/filterseries/.editorconfig create mode 100644 lib/filterseries/.gitignore create mode 100644 lib/filterseries/.jscsrc create mode 100644 lib/filterseries/.jshintrc create mode 100644 lib/filterseries/README.md create mode 100644 lib/filterseries/index.js create mode 100644 lib/filterseries/package.json create mode 100644 lib/forever/.editorconfig create mode 100644 lib/forever/.gitignore create mode 100644 lib/forever/.jscsrc create mode 100644 lib/forever/.jshintrc create mode 100644 lib/forever/README.md create mode 100644 lib/forever/index.js create mode 100644 lib/forever/package.json create mode 100644 lib/index.js create mode 100644 lib/iterator/.editorconfig create mode 100644 lib/iterator/.gitignore create mode 100644 lib/iterator/.jscsrc create mode 100644 lib/iterator/.jshintrc create mode 100644 lib/iterator/README.md create mode 100644 lib/iterator/index.js create mode 100644 lib/iterator/package.json create mode 100644 lib/log/.editorconfig create mode 100644 lib/log/.gitignore create mode 100644 lib/log/.jscsrc create mode 100644 lib/log/.jshintrc create mode 100644 lib/log/README.md create mode 100644 lib/log/index.js create mode 100644 lib/log/package.json create mode 100644 lib/map/.editorconfig create mode 100644 lib/map/.gitignore create mode 100644 lib/map/.jscsrc create mode 100644 lib/map/.jshintrc create mode 100644 lib/map/README.md create mode 100644 lib/map/index.js create mode 100644 lib/map/package.json create mode 100644 lib/maplimit/.editorconfig create mode 100644 lib/maplimit/.gitignore create mode 100644 lib/maplimit/.jscsrc create mode 100644 lib/maplimit/.jshintrc create mode 100644 lib/maplimit/README.md create mode 100644 lib/maplimit/index.js create mode 100644 lib/maplimit/package.json create mode 100644 lib/mapseries/.editorconfig create mode 100644 lib/mapseries/.gitignore create mode 100644 lib/mapseries/.jscsrc create mode 100644 lib/mapseries/.jshintrc create mode 100644 lib/mapseries/README.md create mode 100644 lib/mapseries/index.js create mode 100644 lib/mapseries/package.json create mode 100644 lib/memoize/.editorconfig create mode 100644 lib/memoize/.gitignore create mode 100644 lib/memoize/.jscsrc create mode 100644 lib/memoize/.jshintrc create mode 100644 lib/memoize/README.md create mode 100644 lib/memoize/index.js create mode 100644 lib/memoize/package.json create mode 100644 lib/nexttick/.editorconfig create mode 100644 lib/nexttick/.gitignore create mode 100644 lib/nexttick/.jscsrc create mode 100644 lib/nexttick/.jshintrc create mode 100644 lib/nexttick/README.md create mode 100644 lib/nexttick/index.js create mode 100644 lib/nexttick/package.json create mode 100644 lib/parallel/.editorconfig create mode 100644 lib/parallel/.gitignore create mode 100644 lib/parallel/.jscsrc create mode 100644 lib/parallel/.jshintrc create mode 100644 lib/parallel/README.md create mode 100644 lib/parallel/index.js create mode 100644 lib/parallel/package.json create mode 100644 lib/parallellimit/.editorconfig create mode 100644 lib/parallellimit/.gitignore create mode 100644 lib/parallellimit/.jscsrc create mode 100644 lib/parallellimit/.jshintrc create mode 100644 lib/parallellimit/README.md create mode 100644 lib/parallellimit/index.js create mode 100644 lib/parallellimit/package.json create mode 100644 lib/priorityqueue/.editorconfig create mode 100644 lib/priorityqueue/.gitignore create mode 100644 lib/priorityqueue/.jscsrc create mode 100644 lib/priorityqueue/.jshintrc create mode 100644 lib/priorityqueue/README.md create mode 100644 lib/priorityqueue/index.js create mode 100644 lib/priorityqueue/package.json create mode 100644 lib/queue/.editorconfig create mode 100644 lib/queue/.gitignore create mode 100644 lib/queue/.jscsrc create mode 100644 lib/queue/.jshintrc create mode 100644 lib/queue/README.md create mode 100644 lib/queue/index.js create mode 100644 lib/queue/package.json create mode 100644 lib/reduce/.editorconfig create mode 100644 lib/reduce/.gitignore create mode 100644 lib/reduce/.jscsrc create mode 100644 lib/reduce/.jshintrc create mode 100644 lib/reduce/README.md create mode 100644 lib/reduce/index.js create mode 100644 lib/reduce/package.json create mode 100644 lib/reduceright/.editorconfig create mode 100644 lib/reduceright/.gitignore create mode 100644 lib/reduceright/.jscsrc create mode 100644 lib/reduceright/.jshintrc create mode 100644 lib/reduceright/README.md create mode 100644 lib/reduceright/index.js create mode 100644 lib/reduceright/package.json create mode 100644 lib/reject/.editorconfig create mode 100644 lib/reject/.gitignore create mode 100644 lib/reject/.jscsrc create mode 100644 lib/reject/.jshintrc create mode 100644 lib/reject/README.md create mode 100644 lib/reject/index.js create mode 100644 lib/reject/package.json create mode 100644 lib/rejectlimit/.editorconfig create mode 100644 lib/rejectlimit/.gitignore create mode 100644 lib/rejectlimit/.jscsrc create mode 100644 lib/rejectlimit/.jshintrc create mode 100644 lib/rejectlimit/README.md create mode 100644 lib/rejectlimit/index.js create mode 100644 lib/rejectlimit/package.json create mode 100644 lib/rejectseries/.editorconfig create mode 100644 lib/rejectseries/.gitignore create mode 100644 lib/rejectseries/.jscsrc create mode 100644 lib/rejectseries/.jshintrc create mode 100644 lib/rejectseries/README.md create mode 100644 lib/rejectseries/index.js create mode 100644 lib/rejectseries/package.json create mode 100644 lib/retry/.editorconfig create mode 100644 lib/retry/.gitignore create mode 100644 lib/retry/.jscsrc create mode 100644 lib/retry/.jshintrc create mode 100644 lib/retry/README.md create mode 100644 lib/retry/index.js create mode 100644 lib/retry/package.json create mode 100644 lib/seq/.editorconfig create mode 100644 lib/seq/.gitignore create mode 100644 lib/seq/.jscsrc create mode 100644 lib/seq/.jshintrc create mode 100644 lib/seq/README.md create mode 100644 lib/seq/index.js create mode 100644 lib/seq/package.json create mode 100644 lib/series/.editorconfig create mode 100644 lib/series/.gitignore create mode 100644 lib/series/.jscsrc create mode 100644 lib/series/.jshintrc create mode 100644 lib/series/README.md create mode 100644 lib/series/index.js create mode 100644 lib/series/package.json create mode 100644 lib/setimmediate/.editorconfig create mode 100644 lib/setimmediate/.gitignore create mode 100644 lib/setimmediate/.jscsrc create mode 100644 lib/setimmediate/.jshintrc create mode 100644 lib/setimmediate/README.md create mode 100644 lib/setimmediate/index.js create mode 100644 lib/setimmediate/package.json create mode 100644 lib/some/.editorconfig create mode 100644 lib/some/.gitignore create mode 100644 lib/some/.jscsrc create mode 100644 lib/some/.jshintrc create mode 100644 lib/some/README.md create mode 100644 lib/some/index.js create mode 100644 lib/some/package.json create mode 100644 lib/somelimit/.editorconfig create mode 100644 lib/somelimit/.gitignore create mode 100644 lib/somelimit/.jscsrc create mode 100644 lib/somelimit/.jshintrc create mode 100644 lib/somelimit/README.md create mode 100644 lib/somelimit/index.js create mode 100644 lib/somelimit/package.json create mode 100644 lib/sortby/.editorconfig create mode 100644 lib/sortby/.gitignore create mode 100644 lib/sortby/.jscsrc create mode 100644 lib/sortby/.jshintrc create mode 100644 lib/sortby/README.md create mode 100644 lib/sortby/index.js create mode 100644 lib/sortby/package.json create mode 100644 lib/times/.editorconfig create mode 100644 lib/times/.gitignore create mode 100644 lib/times/.jscsrc create mode 100644 lib/times/.jshintrc create mode 100644 lib/times/README.md create mode 100644 lib/times/index.js create mode 100644 lib/times/package.json create mode 100644 lib/timeslimit/.editorconfig create mode 100644 lib/timeslimit/.gitignore create mode 100644 lib/timeslimit/.jscsrc create mode 100644 lib/timeslimit/.jshintrc create mode 100644 lib/timeslimit/README.md create mode 100644 lib/timeslimit/index.js create mode 100644 lib/timeslimit/package.json create mode 100644 lib/timesseries/.editorconfig create mode 100644 lib/timesseries/.gitignore create mode 100644 lib/timesseries/.jscsrc create mode 100644 lib/timesseries/.jshintrc create mode 100644 lib/timesseries/README.md create mode 100644 lib/timesseries/index.js create mode 100644 lib/timesseries/package.json create mode 100644 lib/transform/.editorconfig create mode 100644 lib/transform/.gitignore create mode 100644 lib/transform/.jscsrc create mode 100644 lib/transform/.jshintrc create mode 100644 lib/transform/README.md create mode 100644 lib/transform/index.js create mode 100644 lib/transform/package.json create mode 100644 lib/unmemoize/.editorconfig create mode 100644 lib/unmemoize/.gitignore create mode 100644 lib/unmemoize/.jscsrc create mode 100644 lib/unmemoize/.jshintrc create mode 100644 lib/unmemoize/README.md create mode 100644 lib/unmemoize/index.js create mode 100644 lib/unmemoize/package.json create mode 100644 lib/until/.editorconfig create mode 100644 lib/until/.gitignore create mode 100644 lib/until/.jscsrc create mode 100644 lib/until/.jshintrc create mode 100644 lib/until/README.md create mode 100644 lib/until/index.js create mode 100644 lib/until/package.json create mode 100644 lib/waterfall/.editorconfig create mode 100644 lib/waterfall/.gitignore create mode 100644 lib/waterfall/.jscsrc create mode 100644 lib/waterfall/.jshintrc create mode 100644 lib/waterfall/README.md create mode 100644 lib/waterfall/index.js create mode 100644 lib/waterfall/package.json create mode 100644 lib/whilst/.editorconfig create mode 100644 lib/whilst/.gitignore create mode 100644 lib/whilst/.jscsrc create mode 100644 lib/whilst/.jshintrc create mode 100644 lib/whilst/README.md create mode 100644 lib/whilst/index.js create mode 100644 lib/whilst/package.json create mode 100644 scripts/each-module.js create mode 100644 scripts/gk.js create mode 100644 scripts/init.js create mode 100644 scripts/publish.js create mode 100644 scripts/push.js create mode 100644 support/dependencies.json create mode 100644 support/module_template.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..7f502d449 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore index 9134974d9..8feeb01fe 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ perf/versions nyc_output coverage *.log +.DS_Store +npm-debug.log diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..4274f795c --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +lib +scripts +support/dependencies.json +support/module_template.md diff --git a/Makefile b/Makefile index 87279f40c..4c90871fa 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,18 @@ export PATH := ./node_modules/.bin/:$(PATH):./bin/ PACKAGE = asyncjs +REQUIRE_NAME = async XYZ = node_modules/.bin/xyz --repo git@github.com:caolan/async.git +BROWSERIFY = node_modules/.bin/browserify BUILDDIR = dist -SRC = lib/async.js +SRC = lib/index.js all: lint test clean build build: $(wildcard lib/*.js) mkdir -p $(BUILDDIR) - cp $(SRC) $(BUILDDIR)/async.js + browserify $(SRC) -o $(BUILDDIR)/async.js -s $(REQUIRE_NAME) uglifyjs $(BUILDDIR)/async.js -mc \ --source-map $(BUILDDIR)/async.min.map \ -o $(BUILDDIR)/async.min.js diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 000000000..2655edff1 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,88 @@ +'use strict'; + +var gulp = require('gulp'); +var path = require('path'); +var fs = require('fs-extra'); +var pkg = require('./package.json'); +var jsonFuture = require('json-future'); +var template = require('lodash.template'); + +var moduleDeps = JSON.parse(template(fs.readFileSync('./support/dependencies.json').toString())({ + version: pkg.version} + )); + +var MODULES_PATH = './lib/'; + +function getFolders(dir) { + return fs.readdirSync(dir) + .filter(function(file) { + return fs.statSync(path.join(dir, file)).isDirectory(); + }); +} + +function generatePackage(name) { + function generateKeywords(name) { + var keywords = [ + 'async', + 'async-modularized' + ]; + + keywords.push(name); + return keywords; + } + + function generateDefaultFields(name) { + var ORIGINAL_FIELDS = [ + 'author', + 'version', + 'repository', + 'license' + ]; + + var structure = { + name: 'async.' + name, + description: 'async ' + name + 'method as module.', + main: './index.js', + repository: "async-js/async." + name + }; + + ORIGINAL_FIELDS.forEach(function(field) { + structure[field] = pkg[field]; + }); + + if (Object.keys(moduleDeps[name]).length > 0) + structure.dependencies = moduleDeps[name]; + + return structure; + } + + var modulePackage = generateDefaultFields(name); + modulePackage.keywords = generateKeywords(name); + return modulePackage; +} + +function generateReadme(name, dist) { + var filepath = path.resolve('support/module_template.md'); + var tpl = fs.readFileSync(filepath).toString(); + tpl = template(tpl)({name: name}); + fs.writeFileSync(dist, tpl); +} + +function copyMetaFiles(dist) { + var files = ['.editorconfig', '.jscsrc', '.jshintrc', '.gitignore']; + + files.forEach(function(file) { + var metafile = path.resolve(file); + var distFile = path.resolve(dist, file); + fs.copySync(metafile, distFile); + }); +} + +gulp.task('package', function() { + return getFolders(MODULES_PATH).map(function(module) { + var dist = path.resolve(MODULES_PATH, module); + jsonFuture.save(path.resolve(dist, 'package.json'), generatePackage(module)); + generateReadme(module, path.resolve(dist, 'README.md')); + copyMetaFiles(dist); + }); +}); diff --git a/lib/apply/.editorconfig b/lib/apply/.editorconfig new file mode 100644 index 000000000..7f502d449 --- /dev/null +++ b/lib/apply/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/lib/apply/.gitignore b/lib/apply/.gitignore new file mode 100644 index 000000000..8feeb01fe --- /dev/null +++ b/lib/apply/.gitignore @@ -0,0 +1,8 @@ +node_modules +dist +perf/versions +nyc_output +coverage +*.log +.DS_Store +npm-debug.log diff --git a/lib/apply/.jscsrc b/lib/apply/.jscsrc new file mode 100644 index 000000000..b8cfa1731 --- /dev/null +++ b/lib/apply/.jscsrc @@ -0,0 +1,3 @@ +{ + "validateIndentation": 4 +} \ No newline at end of file diff --git a/lib/apply/.jshintrc b/lib/apply/.jshintrc new file mode 100644 index 000000000..76be34a84 --- /dev/null +++ b/lib/apply/.jshintrc @@ -0,0 +1,29 @@ +{ + // Enforcing options + "eqeqeq": false, + "forin": true, + "indent": 4, + "noarg": true, + "undef": true, + "unused": true, + "trailing": true, + "evil": true, + "laxcomma": true, + + // Relaxing options + "onevar": false, + "asi": false, + "eqnull": true, + "expr": false, + "loopfunc": true, + "sub": true, + "browser": true, + "node": true, + "globals": { + "self": true, + "define": true, + "describe": true, + "context": true, + "it": true + } +} diff --git a/lib/apply/README.md b/lib/apply/README.md new file mode 100644 index 000000000..3caa57674 --- /dev/null +++ b/lib/apply/README.md @@ -0,0 +1,13 @@ +# async.apply + +![Last version](https://img.shields.io/github/tag/async-js/async.apply.svg?style=flat-square) +[![Dependency status](http://img.shields.io/david/async-js/async.apply.svg?style=flat-square)](https://david-dm.org/async-js/async.apply) +[![Dev Dependencies Status](http://img.shields.io/david/dev/async-js/async.apply.svg?style=flat-square)](https://david-dm.org/async-js/async.apply#info=devDependencies) +[![NPM Status](http://img.shields.io/npm/dm/async.apply.svg?style=flat-square)](https://www.npmjs.org/package/async.apply) +[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/kikobeats) + +> [async#apply](https://github.com/async-js/async#async.apply) method as module. + +## License + +MIT © [async-js](https://github.com/async-js) diff --git a/lib/apply/index.js b/lib/apply/index.js new file mode 100644 index 000000000..e27ef80db --- /dev/null +++ b/lib/apply/index.js @@ -0,0 +1,9 @@ +'use strict'; + +var restParam = require('async.util.restparam'); + +module.exports = restParam(function(fn, args) { + return restParam(function(callArgs) { + return fn.apply(null, args.concat(callArgs)); + }); +}); diff --git a/lib/apply/package.json b/lib/apply/package.json new file mode 100644 index 000000000..6d8e5dc61 --- /dev/null +++ b/lib/apply/package.json @@ -0,0 +1,20 @@ +{ + "name": "async.apply", + "description": "async applymethod as module.", + "main": "./index.js", + "repository": { + "type": "git", + "url": "https://github.com/caolan/async.git" + }, + "author": "Caolan McMahon", + "version": "0.5.2", + "license": "MIT", + "dependencies": { + "async.util.restparam": "0.5.2" + }, + "keywords": [ + "async", + "async-modularized", + "apply" + ] +} diff --git a/lib/applyeach/.editorconfig b/lib/applyeach/.editorconfig new file mode 100644 index 000000000..7f502d449 --- /dev/null +++ b/lib/applyeach/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/lib/applyeach/.gitignore b/lib/applyeach/.gitignore new file mode 100644 index 000000000..8feeb01fe --- /dev/null +++ b/lib/applyeach/.gitignore @@ -0,0 +1,8 @@ +node_modules +dist +perf/versions +nyc_output +coverage +*.log +.DS_Store +npm-debug.log diff --git a/lib/applyeach/.jscsrc b/lib/applyeach/.jscsrc new file mode 100644 index 000000000..b8cfa1731 --- /dev/null +++ b/lib/applyeach/.jscsrc @@ -0,0 +1,3 @@ +{ + "validateIndentation": 4 +} \ No newline at end of file diff --git a/lib/applyeach/.jshintrc b/lib/applyeach/.jshintrc new file mode 100644 index 000000000..76be34a84 --- /dev/null +++ b/lib/applyeach/.jshintrc @@ -0,0 +1,29 @@ +{ + // Enforcing options + "eqeqeq": false, + "forin": true, + "indent": 4, + "noarg": true, + "undef": true, + "unused": true, + "trailing": true, + "evil": true, + "laxcomma": true, + + // Relaxing options + "onevar": false, + "asi": false, + "eqnull": true, + "expr": false, + "loopfunc": true, + "sub": true, + "browser": true, + "node": true, + "globals": { + "self": true, + "define": true, + "describe": true, + "context": true, + "it": true + } +} diff --git a/lib/applyeach/README.md b/lib/applyeach/README.md new file mode 100644 index 000000000..a8e68c33f --- /dev/null +++ b/lib/applyeach/README.md @@ -0,0 +1,13 @@ +# async.applyeach + +![Last version](https://img.shields.io/github/tag/async-js/async.applyeach.svg?style=flat-square) +[![Dependency status](http://img.shields.io/david/async-js/async.applyeach.svg?style=flat-square)](https://david-dm.org/async-js/async.applyeach) +[![Dev Dependencies Status](http://img.shields.io/david/dev/async-js/async.applyeach.svg?style=flat-square)](https://david-dm.org/async-js/async.applyeach#info=devDependencies) +[![NPM Status](http://img.shields.io/npm/dm/async.applyeach.svg?style=flat-square)](https://www.npmjs.org/package/async.applyeach) +[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/kikobeats) + +> [async#applyeach](https://github.com/async-js/async#async.applyeach) method as module. + +## License + +MIT © [async-js](https://github.com/async-js) diff --git a/lib/applyeach/index.js b/lib/applyeach/index.js new file mode 100644 index 000000000..9519afdb4 --- /dev/null +++ b/lib/applyeach/index.js @@ -0,0 +1,6 @@ +'use strict'; + +var eachOf = require('async.eachof'); +var applyEach = require('async.util.applyeach'); + +module.exports = applyEach(eachOf); diff --git a/lib/applyeach/package.json b/lib/applyeach/package.json new file mode 100644 index 000000000..996beca61 --- /dev/null +++ b/lib/applyeach/package.json @@ -0,0 +1,21 @@ +{ + "name": "async.applyeach", + "description": "async applyeachmethod as module.", + "main": "./index.js", + "repository": { + "type": "git", + "url": "https://github.com/caolan/async.git" + }, + "author": "Caolan McMahon", + "version": "0.5.2", + "license": "MIT", + "dependencies": { + "async.eachof": "0.5.2", + "async.util.applyeach": "0.5.2" + }, + "keywords": [ + "async", + "async-modularized", + "applyeach" + ] +} diff --git a/lib/applyeachseries/.editorconfig b/lib/applyeachseries/.editorconfig new file mode 100644 index 000000000..7f502d449 --- /dev/null +++ b/lib/applyeachseries/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/lib/applyeachseries/.gitignore b/lib/applyeachseries/.gitignore new file mode 100644 index 000000000..8feeb01fe --- /dev/null +++ b/lib/applyeachseries/.gitignore @@ -0,0 +1,8 @@ +node_modules +dist +perf/versions +nyc_output +coverage +*.log +.DS_Store +npm-debug.log diff --git a/lib/applyeachseries/.jscsrc b/lib/applyeachseries/.jscsrc new file mode 100644 index 000000000..b8cfa1731 --- /dev/null +++ b/lib/applyeachseries/.jscsrc @@ -0,0 +1,3 @@ +{ + "validateIndentation": 4 +} \ No newline at end of file diff --git a/lib/applyeachseries/.jshintrc b/lib/applyeachseries/.jshintrc new file mode 100644 index 000000000..76be34a84 --- /dev/null +++ b/lib/applyeachseries/.jshintrc @@ -0,0 +1,29 @@ +{ + // Enforcing options + "eqeqeq": false, + "forin": true, + "indent": 4, + "noarg": true, + "undef": true, + "unused": true, + "trailing": true, + "evil": true, + "laxcomma": true, + + // Relaxing options + "onevar": false, + "asi": false, + "eqnull": true, + "expr": false, + "loopfunc": true, + "sub": true, + "browser": true, + "node": true, + "globals": { + "self": true, + "define": true, + "describe": true, + "context": true, + "it": true + } +} diff --git a/lib/applyeachseries/README.md b/lib/applyeachseries/README.md new file mode 100644 index 000000000..bedaee7f0 --- /dev/null +++ b/lib/applyeachseries/README.md @@ -0,0 +1,13 @@ +# async.applyeachseries + +![Last version](https://img.shields.io/github/tag/async-js/async.applyeachseries.svg?style=flat-square) +[![Dependency status](http://img.shields.io/david/async-js/async.applyeachseries.svg?style=flat-square)](https://david-dm.org/async-js/async.applyeachseries) +[![Dev Dependencies Status](http://img.shields.io/david/dev/async-js/async.applyeachseries.svg?style=flat-square)](https://david-dm.org/async-js/async.applyeachseries#info=devDependencies) +[![NPM Status](http://img.shields.io/npm/dm/async.applyeachseries.svg?style=flat-square)](https://www.npmjs.org/package/async.applyeachseries) +[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/kikobeats) + +> [async#applyeachseries](https://github.com/async-js/async#async.applyeachseries) method as module. + +## License + +MIT © [async-js](https://github.com/async-js) diff --git a/lib/applyeachseries/index.js b/lib/applyeachseries/index.js new file mode 100644 index 000000000..8d4d3cfad --- /dev/null +++ b/lib/applyeachseries/index.js @@ -0,0 +1,6 @@ +'use strict'; + +var eachOfSeries = require('async.eachofseries'); +var applyEach = require('async.util.applyeach'); + +module.exports = applyEach(eachOfSeries); diff --git a/lib/applyeachseries/package.json b/lib/applyeachseries/package.json new file mode 100644 index 000000000..70ee71a0d --- /dev/null +++ b/lib/applyeachseries/package.json @@ -0,0 +1,21 @@ +{ + "name": "async.applyeachseries", + "description": "async applyeachseriesmethod as module.", + "main": "./index.js", + "repository": { + "type": "git", + "url": "https://github.com/caolan/async.git" + }, + "author": "Caolan McMahon", + "version": "0.5.2", + "license": "MIT", + "dependencies": { + "async.eachofseries": "0.5.2", + "async.util.applyeach": "0.5.2" + }, + "keywords": [ + "async", + "async-modularized", + "applyeachseries" + ] +} diff --git a/lib/async.js b/lib/async.js deleted file mode 100644 index 3748ac070..000000000 --- a/lib/async.js +++ /dev/null @@ -1,1259 +0,0 @@ -/*! - * async - * https://github.com/caolan/async - * - * Copyright 2010-2014 Caolan McMahon - * Released under the MIT license - */ -(function () { - - var async = {}; - function noop() {} - function identity(v) { - return v; - } - function toBool(v) { - return !!v; - } - function notId(v) { - return !v; - } - - // global on the server, window in the browser - var previous_async; - - // Establish the root object, `window` (`self`) in the browser, `global` - // on the server, or `this` in some virtual machines. We use `self` - // instead of `window` for `WebWorker` support. - var root = typeof self === 'object' && self.self === self && self || - typeof global === 'object' && global.global === global && global || - this; - - if (root != null) { - previous_async = root.async; - } - - async.noConflict = function () { - root.async = previous_async; - return async; - }; - - function only_once(fn) { - return function() { - if (fn === null) throw new Error("Callback was already called."); - fn.apply(this, arguments); - fn = null; - }; - } - - function _once(fn) { - return function() { - if (fn === null) return; - fn.apply(this, arguments); - fn = null; - }; - } - - //// cross-browser compatiblity functions //// - - var _toString = Object.prototype.toString; - - var _isArray = Array.isArray || function (obj) { - return _toString.call(obj) === '[object Array]'; - }; - - // Ported from underscore.js isObject - var _isObject = function(obj) { - var type = typeof obj; - return type === 'function' || type === 'object' && !!obj; - }; - - function _isArrayLike(arr) { - return _isArray(arr) || ( - // has a positive integer length property - typeof arr.length === "number" && - arr.length >= 0 && - arr.length % 1 === 0 - ); - } - - function _arrayEach(arr, iterator) { - var index = -1, - length = arr.length; - - while (++index < length) { - iterator(arr[index], index, arr); - } - } - - function _map(arr, iterator) { - var index = -1, - length = arr.length, - result = Array(length); - - while (++index < length) { - result[index] = iterator(arr[index], index, arr); - } - return result; - } - - function _range(count) { - return _map(Array(count), function (v, i) { return i; }); - } - - function _reduce(arr, iterator, memo) { - _arrayEach(arr, function (x, i, a) { - memo = iterator(memo, x, i, a); - }); - return memo; - } - - function _forEachOf(object, iterator) { - _arrayEach(_keys(object), function (key) { - iterator(object[key], key); - }); - } - - function _indexOf(arr, item) { - for (var i = 0; i < arr.length; i++) { - if (arr[i] === item) return i; - } - return -1; - } - - var _keys = Object.keys || function (obj) { - var keys = []; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - keys.push(k); - } - } - return keys; - }; - - function _keyIterator(coll) { - var i = -1; - var len; - var keys; - if (_isArrayLike(coll)) { - len = coll.length; - return function next() { - i++; - return i < len ? i : null; - }; - } else { - keys = _keys(coll); - len = keys.length; - return function next() { - i++; - return i < len ? keys[i] : null; - }; - } - } - - // Similar to ES6's rest param (http://ariya.ofilabs.com/2013/03/es6-and-rest-parameter.html) - // This accumulates the arguments passed into an array, after a given index. - // From underscore.js (https://github.com/jashkenas/underscore/pull/2140). - function _restParam(func, startIndex) { - startIndex = startIndex == null ? func.length - 1 : +startIndex; - return function() { - var length = Math.max(arguments.length - startIndex, 0); - var rest = Array(length); - for (var index = 0; index < length; index++) { - rest[index] = arguments[index + startIndex]; - } - switch (startIndex) { - case 0: return func.call(this, rest); - case 1: return func.call(this, arguments[0], rest); - } - // Currently unused but handle cases outside of the switch statement: - // var args = Array(startIndex + 1); - // for (index = 0; index < startIndex; index++) { - // args[index] = arguments[index]; - // } - // args[startIndex] = rest; - // return func.apply(this, args); - }; - } - - function _withoutIndex(iterator) { - return function (value, index, callback) { - return iterator(value, callback); - }; - } - - //// exported async module functions //// - - //// nextTick implementation with browser-compatible fallback //// - - // capture the global reference to guard against fakeTimer mocks - var _setImmediate = typeof setImmediate === 'function' && setImmediate; - - var _delay = _setImmediate ? function(fn) { - // not a direct alias for IE10 compatibility - _setImmediate(fn); - } : function(fn) { - setTimeout(fn, 0); - }; - - if (typeof process === 'object' && typeof process.nextTick === 'function') { - async.nextTick = process.nextTick; - } else { - async.nextTick = _delay; - } - async.setImmediate = _setImmediate ? _delay : async.nextTick; - - - async.forEach = - async.each = function (arr, iterator, callback) { - return async.eachOf(arr, _withoutIndex(iterator), callback); - }; - - async.forEachSeries = - async.eachSeries = function (arr, iterator, callback) { - return async.eachOfSeries(arr, _withoutIndex(iterator), callback); - }; - - - async.forEachLimit = - async.eachLimit = function (arr, limit, iterator, callback) { - return _eachOfLimit(limit)(arr, _withoutIndex(iterator), callback); - }; - - async.forEachOf = - async.eachOf = function (object, iterator, callback) { - callback = _once(callback || noop); - object = object || []; - - var iter = _keyIterator(object); - var key, completed = 0; - - while ((key = iter()) != null) { - completed += 1; - iterator(object[key], key, only_once(done)); - } - - if (completed === 0) callback(null); - - function done(err) { - completed--; - if (err) { - callback(err); - } - // Check key is null in case iterator isn't exhausted - // and done resolved synchronously. - else if (key === null && completed <= 0) { - callback(null); - } - } - }; - - async.forEachOfSeries = - async.eachOfSeries = function (obj, iterator, callback) { - callback = _once(callback || noop); - obj = obj || []; - var nextKey = _keyIterator(obj); - var key = nextKey(); - function iterate() { - var sync = true; - if (key === null) { - return callback(null); - } - iterator(obj[key], key, only_once(function (err) { - if (err) { - callback(err); - } - else { - key = nextKey(); - if (key === null) { - return callback(null); - } else { - if (sync) { - async.setImmediate(iterate); - } else { - iterate(); - } - } - } - })); - sync = false; - } - iterate(); - }; - - - - async.forEachOfLimit = - async.eachOfLimit = function (obj, limit, iterator, callback) { - _eachOfLimit(limit)(obj, iterator, callback); - }; - - function _eachOfLimit(limit) { - - return function (obj, iterator, callback) { - callback = _once(callback || noop); - obj = obj || []; - var nextKey = _keyIterator(obj); - if (limit <= 0) { - return callback(null); - } - var done = false; - var running = 0; - var errored = false; - - (function replenish () { - if (done && running <= 0) { - return callback(null); - } - - while (running < limit && !errored) { - var key = nextKey(); - if (key === null) { - done = true; - if (running <= 0) { - callback(null); - } - return; - } - running += 1; - iterator(obj[key], key, only_once(function (err) { - running -= 1; - if (err) { - callback(err); - errored = true; - } - else { - replenish(); - } - })); - } - })(); - }; - } - - - function doParallel(fn) { - return function (obj, iterator, callback) { - return fn(async.eachOf, obj, iterator, callback); - }; - } - function doParallelLimit(fn) { - return function (obj, limit, iterator, callback) { - return fn(_eachOfLimit(limit), obj, iterator, callback); - }; - } - function doSeries(fn) { - return function (obj, iterator, callback) { - return fn(async.eachOfSeries, obj, iterator, callback); - }; - } - - function _asyncMap(eachfn, arr, iterator, callback) { - callback = _once(callback || noop); - arr = arr || []; - var results = _isArrayLike(arr) ? [] : {}; - eachfn(arr, function (value, index, callback) { - iterator(value, function (err, v) { - results[index] = v; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - } - - async.map = doParallel(_asyncMap); - async.mapSeries = doSeries(_asyncMap); - async.mapLimit = doParallelLimit(_asyncMap); - - // reduce only has a series version, as doing reduce in parallel won't - // work in many situations. - async.inject = - async.foldl = - async.reduce = function (arr, memo, iterator, callback) { - async.eachOfSeries(arr, function (x, i, callback) { - iterator(memo, x, function (err, v) { - memo = v; - callback(err); - }); - }, function (err) { - callback(err, memo); - }); - }; - - async.foldr = - async.reduceRight = function (arr, memo, iterator, callback) { - var reversed = _map(arr, identity).reverse(); - async.reduce(reversed, memo, iterator, callback); - }; - - async.transform = function (arr, memo, iterator, callback) { - if (arguments.length === 3) { - callback = iterator; - iterator = memo; - memo = _isArray(arr) ? [] : {}; - } - - async.eachOf(arr, function(v, k, cb) { - iterator(memo, v, k, cb); - }, function(err) { - callback(err, memo); - }); - }; - - function _filter(eachfn, arr, iterator, callback) { - var results = []; - eachfn(arr, function (x, index, callback) { - iterator(x, function (v) { - if (v) { - results.push({index: index, value: x}); - } - callback(); - }); - }, function () { - callback(_map(results.sort(function (a, b) { - return a.index - b.index; - }), function (x) { - return x.value; - })); - }); - } - - async.select = - async.filter = doParallel(_filter); - - async.selectLimit = - async.filterLimit = doParallelLimit(_filter); - - async.selectSeries = - async.filterSeries = doSeries(_filter); - - function _reject(eachfn, arr, iterator, callback) { - _filter(eachfn, arr, function(value, cb) { - iterator(value, function(v) { - cb(!v); - }); - }, callback); - } - async.reject = doParallel(_reject); - async.rejectLimit = doParallelLimit(_reject); - async.rejectSeries = doSeries(_reject); - - function _createTester(eachfn, check, getResult) { - return function(arr, limit, iterator, cb) { - function done() { - if (cb) cb(getResult(false, void 0)); - } - function iteratee(x, _, callback) { - if (!cb) return callback(); - iterator(x, function (v) { - if (cb && check(v)) { - cb(getResult(true, x)); - cb = iterator = false; - } - callback(); - }); - } - if (arguments.length > 3) { - eachfn(arr, limit, iteratee, done); - } else { - cb = iterator; - iterator = limit; - eachfn(arr, iteratee, done); - } - }; - } - - async.any = - async.some = _createTester(async.eachOf, toBool, identity); - - async.someLimit = _createTester(async.eachOfLimit, toBool, identity); - - async.all = - async.every = _createTester(async.eachOf, notId, notId); - - async.everyLimit = _createTester(async.eachOfLimit, notId, notId); - - function _findGetResult(v, x) { - return x; - } - async.detect = _createTester(async.eachOf, identity, _findGetResult); - async.detectSeries = _createTester(async.eachOfSeries, identity, _findGetResult); - async.detectLimit = _createTester(async.eachOfLimit, identity, _findGetResult); - - async.sortBy = function (arr, iterator, callback) { - async.map(arr, function (x, callback) { - iterator(x, function (err, criteria) { - if (err) { - callback(err); - } - else { - callback(null, {value: x, criteria: criteria}); - } - }); - }, function (err, results) { - if (err) { - return callback(err); - } - else { - callback(null, _map(results.sort(comparator), function (x) { - return x.value; - })); - } - - }); - - function comparator(left, right) { - var a = left.criteria, b = right.criteria; - return a < b ? -1 : a > b ? 1 : 0; - } - }; - - async.auto = function (tasks, concurrency, callback) { - if (typeof arguments[1] === 'function') { - // concurrency is optional, shift the args. - callback = concurrency; - concurrency = null; - } - callback = _once(callback || noop); - var keys = _keys(tasks); - var remainingTasks = keys.length; - if (!remainingTasks) { - return callback(null); - } - if (!concurrency) { - concurrency = remainingTasks; - } - - var results = {}; - var runningTasks = 0; - - var listeners = []; - function addListener(fn) { - listeners.unshift(fn); - } - function removeListener(fn) { - var idx = _indexOf(listeners, fn); - if (idx >= 0) listeners.splice(idx, 1); - } - function taskComplete() { - remainingTasks--; - _arrayEach(listeners.slice(0), function (fn) { - fn(); - }); - } - - addListener(function () { - if (!remainingTasks) { - callback(null, results); - } - }); - - _arrayEach(keys, function (k) { - var task = _isArray(tasks[k]) ? tasks[k]: [tasks[k]]; - var taskCallback = _restParam(function(err, args) { - runningTasks--; - if (args.length <= 1) { - args = args[0]; - } - if (err) { - var safeResults = {}; - _forEachOf(results, function(val, rkey) { - safeResults[rkey] = val; - }); - safeResults[k] = args; - callback(err, safeResults); - } - else { - results[k] = args; - async.setImmediate(taskComplete); - } - }); - var requires = task.slice(0, task.length - 1); - // prevent dead-locks - var len = requires.length; - var dep; - while (len--) { - if (!(dep = tasks[requires[len]])) { - throw new Error('Has inexistant dependency'); - } - if (_isArray(dep) && _indexOf(dep, k) >= 0) { - throw new Error('Has cyclic dependencies'); - } - } - function ready() { - return runningTasks < concurrency && _reduce(requires, function (a, x) { - return (a && results.hasOwnProperty(x)); - }, true) && !results.hasOwnProperty(k); - } - if (ready()) { - runningTasks++; - task[task.length - 1](taskCallback, results); - } - else { - addListener(listener); - } - function listener() { - if (ready()) { - runningTasks++; - removeListener(listener); - task[task.length - 1](taskCallback, results); - } - } - }); - }; - - - - async.retry = function(times, task, callback) { - var DEFAULT_TIMES = 5; - var DEFAULT_INTERVAL = 0; - - var attempts = []; - - var opts = { - times: DEFAULT_TIMES, - interval: DEFAULT_INTERVAL - }; - - function parseTimes(acc, t){ - if(typeof t === 'number'){ - acc.times = parseInt(t, 10) || DEFAULT_TIMES; - } else if(typeof t === 'object'){ - acc.times = parseInt(t.times, 10) || DEFAULT_TIMES; - acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL; - } else { - throw new Error('Unsupported argument type for \'times\': ' + typeof t); - } - } - - var length = arguments.length; - if (length < 1 || length > 3) { - throw new Error('Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)'); - } else if (length <= 2 && typeof times === 'function') { - callback = task; - task = times; - } - if (typeof times !== 'function') { - parseTimes(opts, times); - } - opts.callback = callback; - opts.task = task; - - function wrappedTask(wrappedCallback, wrappedResults) { - function retryAttempt(task, finalAttempt) { - return function(seriesCallback) { - task(function(err, result){ - seriesCallback(!err || finalAttempt, {err: err, result: result}); - }, wrappedResults); - }; - } - - function retryInterval(interval){ - return function(seriesCallback){ - setTimeout(function(){ - seriesCallback(null); - }, interval); - }; - } - - while (opts.times) { - - var finalAttempt = !(opts.times-=1); - attempts.push(retryAttempt(opts.task, finalAttempt)); - if(!finalAttempt && opts.interval > 0){ - attempts.push(retryInterval(opts.interval)); - } - } - - async.series(attempts, function(done, data){ - data = data[data.length - 1]; - (wrappedCallback || opts.callback)(data.err, data.result); - }); - } - - // If a callback is passed, run this as a controll flow - return opts.callback ? wrappedTask() : wrappedTask; - }; - - async.waterfall = function (tasks, callback) { - callback = _once(callback || noop); - if (!_isArray(tasks)) { - var err = new Error('First argument to waterfall must be an array of functions'); - return callback(err); - } - if (!tasks.length) { - return callback(); - } - function wrapIterator(iterator) { - return _restParam(function (err, args) { - if (err) { - callback.apply(null, [err].concat(args)); - } - else { - var next = iterator.next(); - if (next) { - args.push(wrapIterator(next)); - } - else { - args.push(callback); - } - ensureAsync(iterator).apply(null, args); - } - }); - } - wrapIterator(async.iterator(tasks))(); - }; - - function _parallel(eachfn, tasks, callback) { - callback = callback || noop; - var results = _isArrayLike(tasks) ? [] : {}; - - eachfn(tasks, function (task, key, callback) { - task(_restParam(function (err, args) { - if (args.length <= 1) { - args = args[0]; - } - results[key] = args; - callback(err); - })); - }, function (err) { - callback(err, results); - }); - } - - async.parallel = function (tasks, callback) { - _parallel(async.eachOf, tasks, callback); - }; - - async.parallelLimit = function(tasks, limit, callback) { - _parallel(_eachOfLimit(limit), tasks, callback); - }; - - async.series = function(tasks, callback) { - _parallel(async.eachOfSeries, tasks, callback); - }; - - async.iterator = function (tasks) { - function makeCallback(index) { - function fn() { - if (tasks.length) { - tasks[index].apply(null, arguments); - } - return fn.next(); - } - fn.next = function () { - return (index < tasks.length - 1) ? makeCallback(index + 1): null; - }; - return fn; - } - return makeCallback(0); - }; - - async.apply = _restParam(function (fn, args) { - return _restParam(function (callArgs) { - return fn.apply( - null, args.concat(callArgs) - ); - }); - }); - - function _concat(eachfn, arr, fn, callback) { - var result = []; - eachfn(arr, function (x, index, cb) { - fn(x, function (err, y) { - result = result.concat(y || []); - cb(err); - }); - }, function (err) { - callback(err, result); - }); - } - async.concat = doParallel(_concat); - async.concatSeries = doSeries(_concat); - - async.whilst = function (test, iterator, callback) { - callback = callback || noop; - if (test()) { - var next = _restParam(function(err, args) { - if (err) { - callback(err); - } else if (test.apply(this, args)) { - iterator(next); - } else { - callback.apply(null, [null].concat(args)); - } - }); - iterator(next); - } else { - callback(null); - } - }; - - async.doWhilst = function (iterator, test, callback) { - var calls = 0; - return async.whilst(function() { - return ++calls <= 1 || test.apply(this, arguments); - }, iterator, callback); - }; - - async.until = function (test, iterator, callback) { - return async.whilst(function() { - return !test.apply(this, arguments); - }, iterator, callback); - }; - - async.doUntil = function (iterator, test, callback) { - return async.doWhilst(iterator, function() { - return !test.apply(this, arguments); - }, callback); - }; - - async.during = function (test, iterator, callback) { - callback = callback || noop; - - var next = _restParam(function(err, args) { - if (err) { - callback(err); - } else { - args.push(check); - test.apply(this, args); - } - }); - - var check = function(err, truth) { - if (err) { - callback(err); - } else if (truth) { - iterator(next); - } else { - callback(null); - } - }; - - test(check); - }; - - async.doDuring = function (iterator, test, callback) { - var calls = 0; - async.during(function(next) { - if (calls++ < 1) { - next(null, true); - } else { - test.apply(this, arguments); - } - }, iterator, callback); - }; - - function _queue(worker, concurrency, payload) { - if (concurrency == null) { - concurrency = 1; - } - else if(concurrency === 0) { - throw new Error('Concurrency must not be zero'); - } - function _insert(q, data, pos, callback) { - if (callback != null && typeof callback !== "function") { - throw new Error("task callback must be a function"); - } - q.started = true; - if (!_isArray(data)) { - data = [data]; - } - if(data.length === 0 && q.idle()) { - // call drain immediately if there are no tasks - return async.setImmediate(function() { - q.drain(); - }); - } - _arrayEach(data, function(task) { - var item = { - data: task, - callback: callback || noop - }; - - if (pos) { - q.tasks.unshift(item); - } else { - q.tasks.push(item); - } - - if (q.tasks.length === q.concurrency) { - q.saturated(); - } - }); - async.setImmediate(q.process); - } - function _next(q, tasks) { - return function(){ - workers -= 1; - - var removed = false; - var args = arguments; - _arrayEach(tasks, function (task) { - _arrayEach(workersList, function (worker, index) { - if (worker === task && !removed) { - workersList.splice(index, 1); - removed = true; - } - }); - - task.callback.apply(task, args); - }); - if (q.tasks.length + workers === 0) { - q.drain(); - } - q.process(); - }; - } - - var workers = 0; - var workersList = []; - var q = { - tasks: [], - concurrency: concurrency, - payload: payload, - saturated: noop, - empty: noop, - drain: noop, - started: false, - paused: false, - push: function (data, callback) { - _insert(q, data, false, callback); - }, - kill: function () { - q.drain = noop; - q.tasks = []; - }, - unshift: function (data, callback) { - _insert(q, data, true, callback); - }, - process: function () { - while(!q.paused && workers < q.concurrency && q.tasks.length){ - - var tasks = q.payload ? - q.tasks.splice(0, q.payload) : - q.tasks.splice(0, q.tasks.length); - - var data = _map(tasks, function (task) { - return task.data; - }); - - if (q.tasks.length === 0) { - q.empty(); - } - workers += 1; - workersList.push(tasks[0]); - var cb = only_once(_next(q, tasks)); - worker(data, cb); - } - }, - length: function () { - return q.tasks.length; - }, - running: function () { - return workers; - }, - workersList: function () { - return workersList; - }, - idle: function() { - return q.tasks.length + workers === 0; - }, - pause: function () { - q.paused = true; - }, - resume: function () { - if (q.paused === false) { return; } - q.paused = false; - var resumeCount = Math.min(q.concurrency, q.tasks.length); - // Need to call q.process once per concurrent - // worker to preserve full concurrency after pause - for (var w = 1; w <= resumeCount; w++) { - async.setImmediate(q.process); - } - } - }; - return q; - } - - async.queue = function (worker, concurrency) { - var q = _queue(function (items, cb) { - worker(items[0], cb); - }, concurrency, 1); - - return q; - }; - - async.priorityQueue = function (worker, concurrency) { - - function _compareTasks(a, b){ - return a.priority - b.priority; - } - - function _binarySearch(sequence, item, compare) { - var beg = -1, - end = sequence.length - 1; - while (beg < end) { - var mid = beg + ((end - beg + 1) >>> 1); - if (compare(item, sequence[mid]) >= 0) { - beg = mid; - } else { - end = mid - 1; - } - } - return beg; - } - - function _insert(q, data, priority, callback) { - if (callback != null && typeof callback !== "function") { - throw new Error("task callback must be a function"); - } - q.started = true; - if (!_isArray(data)) { - data = [data]; - } - if(data.length === 0) { - // call drain immediately if there are no tasks - return async.setImmediate(function() { - q.drain(); - }); - } - _arrayEach(data, function(task) { - var item = { - data: task, - priority: priority, - callback: typeof callback === 'function' ? callback : noop - }; - - q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item); - - if (q.tasks.length === q.concurrency) { - q.saturated(); - } - async.setImmediate(q.process); - }); - } - - // Start with a normal queue - var q = async.queue(worker, concurrency); - - // Override push to accept second parameter representing priority - q.push = function (data, priority, callback) { - _insert(q, data, priority, callback); - }; - - // Remove unshift function - delete q.unshift; - - return q; - }; - - async.cargo = function (worker, payload) { - return _queue(worker, 1, payload); - }; - - function _console_fn(name) { - return _restParam(function (fn, args) { - fn.apply(null, args.concat([_restParam(function (err, args) { - if (typeof console === 'object') { - if (err) { - if (console.error) { - console.error(err); - } - } - else if (console[name]) { - _arrayEach(args, function (x) { - console[name](x); - }); - } - } - })])); - }); - } - async.log = _console_fn('log'); - async.dir = _console_fn('dir'); - /*async.info = _console_fn('info'); - async.warn = _console_fn('warn'); - async.error = _console_fn('error');*/ - - async.memoize = function (fn, hasher) { - var memo = {}; - var queues = {}; - hasher = hasher || identity; - var memoized = _restParam(function memoized(args) { - var callback = args.pop(); - var key = hasher.apply(null, args); - if (key in memo) { - async.setImmediate(function () { - callback.apply(null, memo[key]); - }); - } - else if (key in queues) { - queues[key].push(callback); - } - else { - queues[key] = [callback]; - fn.apply(null, args.concat([_restParam(function (args) { - memo[key] = args; - var q = queues[key]; - delete queues[key]; - for (var i = 0, l = q.length; i < l; i++) { - q[i].apply(null, args); - } - })])); - } - }); - memoized.memo = memo; - memoized.unmemoized = fn; - return memoized; - }; - - async.unmemoize = function (fn) { - return function () { - return (fn.unmemoized || fn).apply(null, arguments); - }; - }; - - function _times(mapper) { - return function (count, iterator, callback) { - mapper(_range(count), iterator, callback); - }; - } - - async.times = _times(async.map); - async.timesSeries = _times(async.mapSeries); - async.timesLimit = function (count, limit, iterator, callback) { - return async.mapLimit(_range(count), limit, iterator, callback); - }; - - async.seq = function (/* functions... */) { - var fns = arguments; - return _restParam(function (args) { - var that = this; - - var callback = args[args.length - 1]; - if (typeof callback == 'function') { - args.pop(); - } else { - callback = noop; - } - - async.reduce(fns, args, function (newargs, fn, cb) { - fn.apply(that, newargs.concat([_restParam(function (err, nextargs) { - cb(err, nextargs); - })])); - }, - function (err, results) { - callback.apply(that, [err].concat(results)); - }); - }); - }; - - async.compose = function (/* functions... */) { - return async.seq.apply(null, Array.prototype.reverse.call(arguments)); - }; - - - function _applyEach(eachfn) { - return _restParam(function(fns, args) { - var go = _restParam(function(args) { - var that = this; - var callback = args.pop(); - return eachfn(fns, function (fn, _, cb) { - fn.apply(that, args.concat([cb])); - }, - callback); - }); - if (args.length) { - return go.apply(this, args); - } - else { - return go; - } - }); - } - - async.applyEach = _applyEach(async.eachOf); - async.applyEachSeries = _applyEach(async.eachOfSeries); - - - async.forever = function (fn, callback) { - var done = only_once(callback || noop); - var task = ensureAsync(fn); - function next(err) { - if (err) { - return done(err); - } - task(next); - } - next(); - }; - - function ensureAsync(fn) { - return _restParam(function (args) { - var callback = args.pop(); - args.push(function () { - var innerArgs = arguments; - if (sync) { - async.setImmediate(function () { - callback.apply(null, innerArgs); - }); - } else { - callback.apply(null, innerArgs); - } - }); - var sync = true; - fn.apply(this, args); - sync = false; - }); - } - - async.ensureAsync = ensureAsync; - - async.constant = _restParam(function(values) { - var args = [null].concat(values); - return function (callback) { - return callback.apply(this, args); - }; - }); - - async.wrapSync = - async.asyncify = function asyncify(func) { - return _restParam(function (args) { - var callback = args.pop(); - var result; - try { - result = func.apply(this, args); - } catch (e) { - return callback(e); - } - // if result is Promise object - if (_isObject(result) && typeof result.then === "function") { - result.then(function(value) { - callback(null, value); - })["catch"](function(err) { - callback(err.message ? err : new Error(err)); - }); - } else { - callback(null, result); - } - }); - }; - - // Node.js - if (typeof module === 'object' && module.exports) { - module.exports = async; - } - // AMD / RequireJS - else if (typeof define === 'function' && define.amd) { - define([], function () { - return async; - }); - } - // included directly via - + + +``` + +## Documentation + +Some functions are also available in the following forms: +* `Series` - the same as `` but runs only a single async operation at a time +* `Limit` - the same as `` but runs a maximum of `limit` async operations at a time + +### Collections + +* [`each`](#each), `eachSeries`, `eachLimit` +* [`forEachOf`](#forEachOf), `forEachOfSeries`, `forEachOfLimit` +* [`map`](#map), `mapSeries`, `mapLimit` +* [`filter`](#filter), `filterSeries`, `filterLimit` +* [`reject`](#reject), `rejectSeries`, `rejectLimit` +* [`reduce`](#reduce), [`reduceRight`](#reduceRight) +* [`detect`](#detect), `detectSeries`, `detectLimit` +* [`sortBy`](#sortBy) +* [`some`](#some), `someLimit` +* [`every`](#every), `everyLimit` +* [`concat`](#concat), `concatSeries` + +### Control Flow + +* [`series`](#seriestasks-callback) +* [`parallel`](#parallel), `parallelLimit` +* [`whilst`](#whilst), [`doWhilst`](#doWhilst) +* [`until`](#until), [`doUntil`](#doUntil) +* [`during`](#during), [`doDuring`](#doDuring) +* [`forever`](#forever) +* [`waterfall`](#waterfall) +* [`compose`](#compose) +* [`seq`](#seq) +* [`applyEach`](#applyEach), `applyEachSeries` +* [`queue`](#queue), [`priorityQueue`](#priorityQueue) +* [`cargo`](#cargo) +* [`auto`](#auto) +* [`retry`](#retry) +* [`iterator`](#iterator) +* [`times`](#times), `timesSeries`, `timesLimit` + +### Utils + +* [`apply`](#apply) +* [`nextTick`](#nextTick) +* [`memoize`](#memoize) +* [`unmemoize`](#unmemoize) +* [`ensureAsync`](#ensureAsync) +* [`constant`](#constant) +* [`asyncify`](#asyncify) +* [`wrapSync`](#wrapSync) +* [`log`](#log) +* [`dir`](#dir) +* [`noConflict`](#noConflict) + +## Collections + + + +### each(arr, iterator, [callback]) + +Applies the function `iterator` to each item in `arr`, in parallel. +The `iterator` is called with an item from the list, and a callback for when it +has finished. If the `iterator` passes an error to its `callback`, the main +`callback` (for the `each` function) is immediately called with the error. + +Note, that since this function applies `iterator` to each item in parallel, +there is no guarantee that the iterator functions will complete in order. + +__Arguments__ + +* `arr` - An array to iterate over. +* `iterator(item, callback)` - A function to apply to each item in `arr`. + The iterator is passed a `callback(err)` which must be called once it has + completed. If no error has occurred, the `callback` should be run without + arguments or with an explicit `null` argument. The array index is not passed + to the iterator. If you need the index, use [`forEachOf`](#forEachOf). +* `callback(err)` - *Optional* A callback which is called when all `iterator` functions + have finished, or an error occurs. + +__Examples__ + + +```js +// assuming openFiles is an array of file names and saveFile is a function +// to save the modified contents of that file: + +async.each(openFiles, saveFile, function(err){ + // if any of the saves produced an error, err would equal that error +}); +``` + +```js +// assuming openFiles is an array of file names + +async.each(openFiles, function(file, callback) { + + // Perform operation on file here. + console.log('Processing file ' + file); + + if( file.length > 32 ) { + console.log('This file name is too long'); + callback('File name too long'); + } else { + // Do work to process file here + console.log('File processed'); + callback(); + } +}, function(err){ + // if any of the file processing produced an error, err would equal that error + if( err ) { + // One of the iterations produced an error. + // All processing will now stop. + console.log('A file failed to process'); + } else { + console.log('All files have been processed successfully'); + } +}); +``` + +__Related__ + +* eachSeries(arr, iterator, [callback]) +* eachLimit(arr, limit, iterator, [callback]) + +--------------------------------------- + + + + +### forEachOf(obj, iterator, [callback]) + +Like `each`, except that it iterates over objects, and passes the key as the second argument to the iterator. + +__Arguments__ + +* `obj` - An object or array to iterate over. +* `iterator(item, key, callback)` - A function to apply to each item in `obj`. +The `key` is the item's key, or index in the case of an array. The iterator is +passed a `callback(err)` which must be called once it has completed. If no +error has occurred, the callback should be run without arguments or with an +explicit `null` argument. +* `callback(err)` - *Optional* A callback which is called when all `iterator` functions have finished, or an error occurs. + +__Example__ + +```js +var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"}; +var configs = {}; + +async.forEachOf(obj, function (value, key, callback) { + fs.readFile(__dirname + value, "utf8", function (err, data) { + if (err) return callback(err); + try { + configs[key] = JSON.parse(data); + } catch (e) { + return callback(e); + } + callback(); + }) +}, function (err) { + if (err) console.error(err.message); + // configs is now a map of JSON data + doSomethingWith(configs); +}) +``` + +__Related__ + +* forEachOfSeries(obj, iterator, [callback]) +* forEachOfLimit(obj, limit, iterator, [callback]) + +--------------------------------------- + + +### map(arr, iterator, [callback]) + +Produces a new array of values by mapping each value in `arr` through +the `iterator` function. The `iterator` is called with an item from `arr` and a +callback for when it has finished processing. Each of these callback takes 2 arguments: +an `error`, and the transformed item from `arr`. If `iterator` passes an error to its +callback, the main `callback` (for the `map` function) is immediately called with the error. + +Note, that since this function applies the `iterator` to each item in parallel, +there is no guarantee that the `iterator` functions will complete in order. +However, the results array will be in the same order as the original `arr`. + +__Arguments__ + +* `arr` - An array to iterate over. +* `iterator(item, callback)` - A function to apply to each item in `arr`. + The iterator is passed a `callback(err, transformed)` which must be called once + it has completed with an error (which can be `null`) and a transformed item. +* `callback(err, results)` - *Optional* A callback which is called when all `iterator` + functions have finished, or an error occurs. Results is an array of the + transformed items from the `arr`. + +__Example__ + +```js +async.map(['file1','file2','file3'], fs.stat, function(err, results){ + // results is now an array of stats for each file +}); +``` + +__Related__ +* mapSeries(arr, iterator, [callback]) +* mapLimit(arr, limit, iterator, [callback]) + +--------------------------------------- + + + +### filter(arr, iterator, [callback]) + +__Alias:__ `select` + +Returns a new array of all the values in `arr` which pass an async truth test. +_The callback for each `iterator` call only accepts a single argument of `true` or +`false`; it does not accept an error argument first!_ This is in-line with the +way node libraries work with truth tests like `fs.exists`. This operation is +performed in parallel, but the results array will be in the same order as the +original. + +__Arguments__ + +* `arr` - An array to iterate over. +* `iterator(item, callback)` - A truth test to apply to each item in `arr`. + The `iterator` is passed a `callback(truthValue)`, which must be called with a + boolean argument once it has completed. +* `callback(results)` - *Optional* A callback which is called after all the `iterator` + functions have finished. + +__Example__ + +```js +async.filter(['file1','file2','file3'], fs.exists, function(results){ + // results now equals an array of the existing files +}); +``` + +__Related__ + +* filterSeries(arr, iterator, [callback]) +* filterLimit(arr, limit, iterator, [callback]) + +--------------------------------------- + + +### reject(arr, iterator, [callback]) + +The opposite of [`filter`](#filter). Removes values that pass an `async` truth test. + +__Related__ + +* rejectSeries(arr, iterator, [callback]) +* rejectLimit(arr, limit, iterator, [callback]) + +--------------------------------------- + + +### reduce(arr, memo, iterator, [callback]) + +__Aliases:__ `inject`, `foldl` + +Reduces `arr` into a single value using an async `iterator` to return +each successive step. `memo` is the initial state of the reduction. +This function only operates in series. + +For performance reasons, it may make sense to split a call to this function into +a parallel map, and then use the normal `Array.prototype.reduce` on the results. +This function is for situations where each step in the reduction needs to be async; +if you can get the data before reducing it, then it's probably a good idea to do so. + +__Arguments__ + +* `arr` - An array to iterate over. +* `memo` - The initial state of the reduction. +* `iterator(memo, item, callback)` - A function applied to each item in the + array to produce the next step in the reduction. The `iterator` is passed a + `callback(err, reduction)` which accepts an optional error as its first + argument, and the state of the reduction as the second. If an error is + passed to the callback, the reduction is stopped and the main `callback` is + immediately called with the error. +* `callback(err, result)` - *Optional* A callback which is called after all the `iterator` + functions have finished. Result is the reduced value. + +__Example__ + +```js +async.reduce([1,2,3], 0, function(memo, item, callback){ + // pointless async: + process.nextTick(function(){ + callback(null, memo + item) + }); +}, function(err, result){ + // result is now equal to the last value of memo, which is 6 +}); +``` + +--------------------------------------- + + +### reduceRight(arr, memo, iterator, [callback]) + +__Alias:__ `foldr` + +Same as [`reduce`](#reduce), only operates on `arr` in reverse order. + + +--------------------------------------- + + +### detect(arr, iterator, [callback]) + +Returns the first value in `arr` that passes an async truth test. The +`iterator` is applied in parallel, meaning the first iterator to return `true` will +fire the detect `callback` with that result. That means the result might not be +the first item in the original `arr` (in terms of order) that passes the test. + +If order within the original `arr` is important, then look at [`detectSeries`](#detectSeries). + +__Arguments__ + +* `arr` - An array to iterate over. +* `iterator(item, callback)` - A truth test to apply to each item in `arr`. + The iterator is passed a `callback(truthValue)` which must be called with a + boolean argument once it has completed. **Note: this callback does not take an error as its first argument.** +* `callback(result)` - *Optional* A callback which is called as soon as any iterator returns + `true`, or after all the `iterator` functions have finished. Result will be + the first item in the array that passes the truth test (iterator) or the + value `undefined` if none passed. **Note: this callback does not take an error as its first argument.** + +__Example__ + +```js +async.detect(['file1','file2','file3'], fs.exists, function(result){ + // result now equals the first file in the list that exists +}); +``` + +__Related__ + +* detectSeries(arr, iterator, [callback]) +* detectLimit(arr, limit, iterator, [callback]) + +--------------------------------------- + + +### sortBy(arr, iterator, [callback]) + +Sorts a list by the results of running each `arr` value through an async `iterator`. + +__Arguments__ + +* `arr` - An array to iterate over. +* `iterator(item, callback)` - A function to apply to each item in `arr`. + The iterator is passed a `callback(err, sortValue)` which must be called once it + has completed with an error (which can be `null`) and a value to use as the sort + criteria. +* `callback(err, results)` - *Optional* A callback which is called after all the `iterator` + functions have finished, or an error occurs. Results is the items from + the original `arr` sorted by the values returned by the `iterator` calls. + +__Example__ + +```js +async.sortBy(['file1','file2','file3'], function(file, callback){ + fs.stat(file, function(err, stats){ + callback(err, stats.mtime); + }); +}, function(err, results){ + // results is now the original array of files sorted by + // modified date +}); +``` + +__Sort Order__ + +By modifying the callback parameter the sorting order can be influenced: + +```js +//ascending order +async.sortBy([1,9,3,5], function(x, callback){ + callback(null, x); +}, function(err,result){ + //result callback +} ); + +//descending order +async.sortBy([1,9,3,5], function(x, callback){ + callback(null, x*-1); //<- x*-1 instead of x, turns the order around +}, function(err,result){ + //result callback +} ); +``` + +--------------------------------------- + + +### some(arr, iterator, [callback]) + +__Alias:__ `any` + +Returns `true` if at least one element in the `arr` satisfies an async test. +_The callback for each iterator call only accepts a single argument of `true` or +`false`; it does not accept an error argument first!_ This is in-line with the +way node libraries work with truth tests like `fs.exists`. Once any iterator +call returns `true`, the main `callback` is immediately called. + +__Arguments__ + +* `arr` - An array to iterate over. +* `iterator(item, callback)` - A truth test to apply to each item in the array + in parallel. The iterator is passed a `callback(truthValue)`` which must be + called with a boolean argument once it has completed. +* `callback(result)` - *Optional* A callback which is called as soon as any iterator returns + `true`, or after all the iterator functions have finished. Result will be + either `true` or `false` depending on the values of the async tests. + + **Note: the callbacks do not take an error as their first argument.** +__Example__ + +```js +async.some(['file1','file2','file3'], fs.exists, function(result){ + // if result is true then at least one of the files exists +}); +``` + +__Related__ + +* someLimit(arr, limit, iterator, callback) + +--------------------------------------- + + +### every(arr, iterator, [callback]) + +__Alias:__ `all` + +Returns `true` if every element in `arr` satisfies an async test. +_The callback for each `iterator` call only accepts a single argument of `true` or +`false`; it does not accept an error argument first!_ This is in-line with the +way node libraries work with truth tests like `fs.exists`. + +__Arguments__ + +* `arr` - An array to iterate over. +* `iterator(item, callback)` - A truth test to apply to each item in the array + in parallel. The iterator is passed a `callback(truthValue)` which must be + called with a boolean argument once it has completed. +* `callback(result)` - *Optional* A callback which is called as soon as any iterator returns + `false`, or after all the iterator functions have finished. Result will be + either `true` or `false` depending on the values of the async tests. + + **Note: the callbacks do not take an error as their first argument.** + +__Example__ + +```js +async.every(['file1','file2','file3'], fs.exists, function(result){ + // if result is true then every file exists +}); +``` + +__Related__ + +* everyLimit(arr, limit, iterator, callback) + +--------------------------------------- + + +### concat(arr, iterator, [callback]) + +Applies `iterator` to each item in `arr`, concatenating the results. Returns the +concatenated list. The `iterator`s are called in parallel, and the results are +concatenated as they return. There is no guarantee that the results array will +be returned in the original order of `arr` passed to the `iterator` function. + +__Arguments__ + +* `arr` - An array to iterate over. +* `iterator(item, callback)` - A function to apply to each item in `arr`. + The iterator is passed a `callback(err, results)` which must be called once it + has completed with an error (which can be `null`) and an array of results. +* `callback(err, results)` - *Optional* A callback which is called after all the `iterator` + functions have finished, or an error occurs. Results is an array containing + the concatenated results of the `iterator` function. + +__Example__ + +```js +async.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files){ + // files is now a list of filenames that exist in the 3 directories +}); +``` + +__Related__ + +* concatSeries(arr, iterator, [callback]) + + +## Control Flow + + +### series(tasks, [callback]) + +Run the functions in the `tasks` array in series, each one running once the previous +function has completed. If any functions in the series pass an error to its +callback, no more functions are run, and `callback` is immediately called with the value of the error. +Otherwise, `callback` receives an array of results when `tasks` have completed. + +It is also possible to use an object instead of an array. Each property will be +run as a function, and the results will be passed to the final `callback` as an object +instead of an array. This can be a more readable way of handling results from +[`series`](#series). + +**Note** that while many implementations preserve the order of object properties, the +[ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6) +explicitly states that + +> The mechanics and order of enumerating the properties is not specified. + +So if you rely on the order in which your series of functions are executed, and want +this to work on all platforms, consider using an array. + +__Arguments__ + +* `tasks` - An array or object containing functions to run, each function is passed + a `callback(err, result)` it must call on completion with an error `err` (which can + be `null`) and an optional `result` value. +* `callback(err, results)` - An optional callback to run once all the functions + have completed. This function gets a results array (or object) containing all + the result arguments passed to the `task` callbacks. + +__Example__ + +```js +async.series([ + function(callback){ + // do some stuff ... + callback(null, 'one'); + }, + function(callback){ + // do some more stuff ... + callback(null, 'two'); + } +], +// optional callback +function(err, results){ + // results is now equal to ['one', 'two'] +}); + + +// an example using an object instead of an array +async.series({ + one: function(callback){ + setTimeout(function(){ + callback(null, 1); + }, 200); + }, + two: function(callback){ + setTimeout(function(){ + callback(null, 2); + }, 100); + } +}, +function(err, results) { + // results is now equal to: {one: 1, two: 2} +}); +``` + +--------------------------------------- + + +### parallel(tasks, [callback]) + +Run the `tasks` array of functions in parallel, without waiting until the previous +function has completed. If any of the functions pass an error to its +callback, the main `callback` is immediately called with the value of the error. +Once the `tasks` have completed, the results are passed to the final `callback` as an +array. + +**Note:** `parallel` is about kicking-off I/O tasks in parallel, not about parallel execution of code. If your tasks do not use any timers or perform any I/O, they will actually be executed in series. Any synchronous setup sections for each task will happen one after the other. JavaScript remains single-threaded. + +It is also possible to use an object instead of an array. Each property will be +run as a function and the results will be passed to the final `callback` as an object +instead of an array. This can be a more readable way of handling results from +[`parallel`](#parallel). + + +__Arguments__ + +* `tasks` - An array or object containing functions to run. Each function is passed + a `callback(err, result)` which it must call on completion with an error `err` + (which can be `null`) and an optional `result` value. +* `callback(err, results)` - An optional callback to run once all the functions + have completed successfully. This function gets a results array (or object) containing all + the result arguments passed to the task callbacks. + +__Example__ + +```js +async.parallel([ + function(callback){ + setTimeout(function(){ + callback(null, 'one'); + }, 200); + }, + function(callback){ + setTimeout(function(){ + callback(null, 'two'); + }, 100); + } +], +// optional callback +function(err, results){ + // the results array will equal ['one','two'] even though + // the second function had a shorter timeout. +}); + + +// an example using an object instead of an array +async.parallel({ + one: function(callback){ + setTimeout(function(){ + callback(null, 1); + }, 200); + }, + two: function(callback){ + setTimeout(function(){ + callback(null, 2); + }, 100); + } +}, +function(err, results) { + // results is now equals to: {one: 1, two: 2} +}); +``` + +__Related__ + +* parallelLimit(tasks, limit, [callback]) + +--------------------------------------- + + +### whilst(test, fn, callback) + +Repeatedly call `fn`, while `test` returns `true`. Calls `callback` when stopped, +or an error occurs. + +__Arguments__ + +* `test()` - synchronous truth test to perform before each execution of `fn`. +* `fn(callback)` - A function which is called each time `test` passes. The function is + passed a `callback(err)`, which must be called once it has completed with an + optional `err` argument. +* `callback(err, [results])` - A callback which is called after the test + function has failed and repeated execution of `fn` has stopped. `callback` + will be passed an error and any arguments passed to the final `fn`'s callback. + +__Example__ + +```js +var count = 0; + +async.whilst( + function () { return count < 5; }, + function (callback) { + count++; + setTimeout(function () { + callback(null, count); + }, 1000); + }, + function (err, n) { + // 5 seconds have passed, n = 5 + } +); +``` + +--------------------------------------- + + +### doWhilst(fn, test, callback) + +The post-check version of [`whilst`](#whilst). To reflect the difference in +the order of operations, the arguments `test` and `fn` are switched. + +`doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript. + +--------------------------------------- + + +### until(test, fn, callback) + +Repeatedly call `fn` until `test` returns `true`. Calls `callback` when stopped, +or an error occurs. `callback` will be passed an error and any arguments passed +to the final `fn`'s callback. + +The inverse of [`whilst`](#whilst). + +--------------------------------------- + + +### doUntil(fn, test, callback) + +Like [`doWhilst`](#doWhilst), except the `test` is inverted. Note the argument ordering differs from `until`. + +--------------------------------------- + + +### during(test, fn, callback) + +Like [`whilst`](#whilst), except the `test` is an asynchronous function that is passed a callback in the form of `function (err, truth)`. If error is passed to `test` or `fn`, the main callback is immediately called with the value of the error. + +__Example__ + +```js +var count = 0; + +async.during( + function (callback) { + return callback(null, count < 5); + }, + function (callback) { + count++; + setTimeout(callback, 1000); + }, + function (err) { + // 5 seconds have passed + } +); +``` + +--------------------------------------- + + +### doDuring(fn, test, callback) + +The post-check version of [`during`](#during). To reflect the difference in +the order of operations, the arguments `test` and `fn` are switched. + +Also a version of [`doWhilst`](#doWhilst) with asynchronous `test` function. + +--------------------------------------- + + +### forever(fn, [errback]) + +Calls the asynchronous function `fn` with a callback parameter that allows it to +call itself again, in series, indefinitely. + +If an error is passed to the callback then `errback` is called with the +error, and execution stops, otherwise it will never be called. + +```js +async.forever( + function(next) { + // next is suitable for passing to things that need a callback(err [, whatever]); + // it will result in this function being called again. + }, + function(err) { + // if next is called with a value in its first parameter, it will appear + // in here as 'err', and execution will stop. + } +); +``` + +--------------------------------------- + + +### waterfall(tasks, [callback]) + +Runs the `tasks` array of functions in series, each passing their results to the next in +the array. However, if any of the `tasks` pass an error to their own callback, the +next function is not executed, and the main `callback` is immediately called with +the error. + +__Arguments__ + +* `tasks` - An array of functions to run, each function is passed a + `callback(err, result1, result2, ...)` it must call on completion. The first + argument is an error (which can be `null`) and any further arguments will be + passed as arguments in order to the next task. +* `callback(err, [results])` - An optional callback to run once all the functions + have completed. This will be passed the results of the last task's callback. + + + +__Example__ + +```js +async.waterfall([ + function(callback) { + callback(null, 'one', 'two'); + }, + function(arg1, arg2, callback) { + // arg1 now equals 'one' and arg2 now equals 'two' + callback(null, 'three'); + }, + function(arg1, callback) { + // arg1 now equals 'three' + callback(null, 'done'); + } +], function (err, result) { + // result now equals 'done' +}); +``` + +--------------------------------------- + +### compose(fn1, fn2...) + +Creates a function which is a composition of the passed asynchronous +functions. Each function consumes the return value of the function that +follows. Composing functions `f()`, `g()`, and `h()` would produce the result of +`f(g(h()))`, only this version uses callbacks to obtain the return values. + +Each function is executed with the `this` binding of the composed function. + +__Arguments__ + +* `functions...` - the asynchronous functions to compose + + +__Example__ + +```js +function add1(n, callback) { + setTimeout(function () { + callback(null, n + 1); + }, 10); +} + +function mul3(n, callback) { + setTimeout(function () { + callback(null, n * 3); + }, 10); +} + +var add1mul3 = async.compose(mul3, add1); + +add1mul3(4, function (err, result) { + // result now equals 15 +}); +``` + +--------------------------------------- + +### seq(fn1, fn2...) + +Version of the compose function that is more natural to read. +Each function consumes the return value of the previous function. +It is the equivalent of [`compose`](#compose) with the arguments reversed. + +Each function is executed with the `this` binding of the composed function. + +__Arguments__ + +* `functions...` - the asynchronous functions to compose + + +__Example__ + +```js +// Requires lodash (or underscore), express3 and dresende's orm2. +// Part of an app, that fetches cats of the logged user. +// This example uses `seq` function to avoid overnesting and error +// handling clutter. +app.get('/cats', function(request, response) { + var User = request.models.User; + async.seq( + _.bind(User.get, User), // 'User.get' has signature (id, callback(err, data)) + function(user, fn) { + user.getCats(fn); // 'getCats' has signature (callback(err, data)) + } + )(req.session.user_id, function (err, cats) { + if (err) { + console.error(err); + response.json({ status: 'error', message: err.message }); + } else { + response.json({ status: 'ok', message: 'Cats found', data: cats }); + } + }); +}); +``` + +--------------------------------------- + +### applyEach(fns, args..., callback) + +Applies the provided arguments to each function in the array, calling +`callback` after all functions have completed. If you only provide the first +argument, then it will return a function which lets you pass in the +arguments as if it were a single function call. + +__Arguments__ + +* `fns` - the asynchronous functions to all call with the same arguments +* `args...` - any number of separate arguments to pass to the function +* `callback` - the final argument should be the callback, called when all + functions have completed processing + + +__Example__ + +```js +async.applyEach([enableSearch, updateSchema], 'bucket', callback); + +// partial application example: +async.each( + buckets, + async.applyEach([enableSearch, updateSchema]), + callback +); +``` + +__Related__ + +* applyEachSeries(tasks, args..., [callback]) + +--------------------------------------- + + +### queue(worker, [concurrency]) + +Creates a `queue` object with the specified `concurrency`. Tasks added to the +`queue` are processed in parallel (up to the `concurrency` limit). If all +`worker`s are in progress, the task is queued until one becomes available. +Once a `worker` completes a `task`, that `task`'s callback is called. + +__Arguments__ + +* `worker(task, callback)` - An asynchronous function for processing a queued + task, which must call its `callback(err)` argument when finished, with an + optional `error` as an argument. If you want to handle errors from an individual task, pass a callback to `q.push()`. +* `concurrency` - An `integer` for determining how many `worker` functions should be + run in parallel. If omitted, the concurrency defaults to `1`. If the concurrency is `0`, an error is thrown. + +__Queue objects__ + +The `queue` object returned by this function has the following properties and +methods: + +* `length()` - a function returning the number of items waiting to be processed. +* `started` - a function returning whether or not any items have been pushed and processed by the queue +* `running()` - a function returning the number of items currently being processed. +* `workersList()` - a function returning the array of items currently being processed. +* `idle()` - a function returning false if there are items waiting or being processed, or true if not. +* `concurrency` - an integer for determining how many `worker` functions should be + run in parallel. This property can be changed after a `queue` is created to + alter the concurrency on-the-fly. +* `push(task, [callback])` - add a new task to the `queue`. Calls `callback` once + the `worker` has finished processing the task. Instead of a single task, a `tasks` array + can be submitted. The respective callback is used for every task in the list. +* `unshift(task, [callback])` - add a new task to the front of the `queue`. +* `saturated` - a callback that is called when the `queue` length hits the `concurrency` limit, + and further tasks will be queued. +* `empty` - a callback that is called when the last item from the `queue` is given to a `worker`. +* `drain` - a callback that is called when the last item from the `queue` has returned from the `worker`. +* `paused` - a boolean for determining whether the queue is in a paused state +* `pause()` - a function that pauses the processing of tasks until `resume()` is called. +* `resume()` - a function that resumes the processing of queued tasks when the queue is paused. +* `kill()` - a function that removes the `drain` callback and empties remaining tasks from the queue forcing it to go idle. + +__Example__ + +```js +// create a queue object with concurrency 2 + +var q = async.queue(function (task, callback) { + console.log('hello ' + task.name); + callback(); +}, 2); + + +// assign a callback +q.drain = function() { + console.log('all items have been processed'); +} + +// add some items to the queue + +q.push({name: 'foo'}, function (err) { + console.log('finished processing foo'); +}); +q.push({name: 'bar'}, function (err) { + console.log('finished processing bar'); +}); + +// add some items to the queue (batch-wise) + +q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function (err) { + console.log('finished processing item'); +}); + +// add some items to the front of the queue + +q.unshift({name: 'bar'}, function (err) { + console.log('finished processing bar'); +}); +``` + + +--------------------------------------- + + +### priorityQueue(worker, concurrency) + +The same as [`queue`](#queue) only tasks are assigned a priority and completed in ascending priority order. There are two differences between `queue` and `priorityQueue` objects: + +* `push(task, priority, [callback])` - `priority` should be a number. If an array of + `tasks` is given, all tasks will be assigned the same priority. +* The `unshift` method was removed. + +--------------------------------------- + + +### cargo(worker, [payload]) + +Creates a `cargo` object with the specified payload. Tasks added to the +cargo will be processed altogether (up to the `payload` limit). If the +`worker` is in progress, the task is queued until it becomes available. Once +the `worker` has completed some tasks, each callback of those tasks is called. +Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966) for how `cargo` and `queue` work. + +While [queue](#queue) passes only one task to one of a group of workers +at a time, cargo passes an array of tasks to a single worker, repeating +when the worker is finished. + +__Arguments__ + +* `worker(tasks, callback)` - An asynchronous function for processing an array of + queued tasks, which must call its `callback(err)` argument when finished, with + an optional `err` argument. +* `payload` - An optional `integer` for determining how many tasks should be + processed per round; if omitted, the default is unlimited. + +__Cargo objects__ + +The `cargo` object returned by this function has the following properties and +methods: + +* `length()` - A function returning the number of items waiting to be processed. +* `payload` - An `integer` for determining how many tasks should be + process per round. This property can be changed after a `cargo` is created to + alter the payload on-the-fly. +* `push(task, [callback])` - Adds `task` to the `queue`. The callback is called + once the `worker` has finished processing the task. Instead of a single task, an array of `tasks` + can be submitted. The respective callback is used for every task in the list. +* `saturated` - A callback that is called when the `queue.length()` hits the concurrency and further tasks will be queued. +* `empty` - A callback that is called when the last item from the `queue` is given to a `worker`. +* `drain` - A callback that is called when the last item from the `queue` has returned from the `worker`. +* `idle()`, `pause()`, `resume()`, `kill()` - cargo inherits all of the same methods and event calbacks as [`queue`](#queue) + +__Example__ + +```js +// create a cargo object with payload 2 + +var cargo = async.cargo(function (tasks, callback) { + for(var i=0; i +### auto(tasks, [concurrency], [callback]) + +Determines the best order for running the functions in `tasks`, based on their requirements. Each function can optionally depend on other functions being completed first, and each function is run as soon as its requirements are satisfied. + +If any of the functions pass an error to their callback, the `auto` sequence will stop. Further tasks will not execute (so any other functions depending on it will not run), and the main `callback` is immediately called with the error. Functions also receive an object containing the results of functions which have completed so far. + +Note, all functions are called with a `results` object as a second argument, +so it is unsafe to pass functions in the `tasks` object which cannot handle the +extra argument. + +For example, this snippet of code: + +```js +async.auto({ + readData: async.apply(fs.readFile, 'data.txt', 'utf-8') +}, callback); +``` + +will have the effect of calling `readFile` with the results object as the last +argument, which will fail: + +```js +fs.readFile('data.txt', 'utf-8', cb, {}); +``` + +Instead, wrap the call to `readFile` in a function which does not forward the +`results` object: + +```js +async.auto({ + readData: function(cb, results){ + fs.readFile('data.txt', 'utf-8', cb); + } +}, callback); +``` + +__Arguments__ + +* `tasks` - An object. Each of its properties is either a function or an array of + requirements, with the function itself the last item in the array. The object's key + of a property serves as the name of the task defined by that property, + i.e. can be used when specifying requirements for other tasks. + The function receives two arguments: (1) a `callback(err, result)` which must be + called when finished, passing an `error` (which can be `null`) and the result of + the function's execution, and (2) a `results` object, containing the results of + the previously executed functions. +* `concurrency` - An optional `integer` for determining the maximum number of tasks that can be run in parallel. By default, as many as possible. +* `callback(err, results)` - An optional callback which is called when all the + tasks have been completed. It receives the `err` argument if any `tasks` + pass an error to their callback. Results are always returned; however, if + an error occurs, no further `tasks` will be performed, and the results + object will only contain partial results. + + +__Example__ + +```js +async.auto({ + get_data: function(callback){ + console.log('in get_data'); + // async code to get some data + callback(null, 'data', 'converted to array'); + }, + make_folder: function(callback){ + console.log('in make_folder'); + // async code to create a directory to store a file in + // this is run at the same time as getting the data + callback(null, 'folder'); + }, + write_file: ['get_data', 'make_folder', function(callback, results){ + console.log('in write_file', JSON.stringify(results)); + // once there is some data and the directory exists, + // write the data to a file in the directory + callback(null, 'filename'); + }], + email_link: ['write_file', function(callback, results){ + console.log('in email_link', JSON.stringify(results)); + // once the file is written let's email a link to it... + // results.write_file contains the filename returned by write_file. + callback(null, {'file':results.write_file, 'email':'user@example.com'}); + }] +}, function(err, results) { + console.log('err = ', err); + console.log('results = ', results); +}); +``` + +This is a fairly trivial example, but to do this using the basic parallel and +series functions would look like this: + +```js +async.parallel([ + function(callback){ + console.log('in get_data'); + // async code to get some data + callback(null, 'data', 'converted to array'); + }, + function(callback){ + console.log('in make_folder'); + // async code to create a directory to store a file in + // this is run at the same time as getting the data + callback(null, 'folder'); + } +], +function(err, results){ + async.series([ + function(callback){ + console.log('in write_file', JSON.stringify(results)); + // once there is some data and the directory exists, + // write the data to a file in the directory + results.push('filename'); + callback(null); + }, + function(callback){ + console.log('in email_link', JSON.stringify(results)); + // once the file is written let's email a link to it... + callback(null, {'file':results.pop(), 'email':'user@example.com'}); + } + ]); +}); +``` + +For a complicated series of `async` tasks, using the [`auto`](#auto) function makes adding +new tasks much easier (and the code more readable). + + +--------------------------------------- + + +### retry([opts = {times: 5, interval: 0}| 5], task, [callback]) + +Attempts to get a successful response from `task` no more than `times` times before +returning an error. If the task is successful, the `callback` will be passed the result +of the successful task. If all attempts fail, the callback will be passed the error and +result (if any) of the final attempt. + +__Arguments__ + +* `opts` - Can be either an object with `times` and `interval` or a number. `times` is how many attempts should be made before giving up. `interval` is how long to wait inbetween attempts. Defaults to {times: 5, interval: 0} + * if a number is passed in it sets `times` only (with `interval` defaulting to 0). +* `task(callback, results)` - A function which receives two arguments: (1) a `callback(err, result)` + which must be called when finished, passing `err` (which can be `null`) and the `result` of + the function's execution, and (2) a `results` object, containing the results of + the previously executed functions (if nested inside another control flow). +* `callback(err, results)` - An optional callback which is called when the + task has succeeded, or after the final failed attempt. It receives the `err` and `result` arguments of the last attempt at completing the `task`. + +The [`retry`](#retry) function can be used as a stand-alone control flow by passing a +callback, as shown below: + +```js +async.retry(3, apiMethod, function(err, result) { + // do something with the result +}); +``` + +```js +async.retry({times: 3, interval: 200}, apiMethod, function(err, result) { + // 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: + +```js +async.auto({ + users: api.getUsers.bind(api), + payments: async.retry(3, api.getPayments.bind(api)) +}, function(err, results) { + // do something with the results +}); +``` + + +--------------------------------------- + + +### iterator(tasks) + +Creates an iterator function which calls the next function in the `tasks` array, +returning a continuation to call the next one after that. It's also possible to +“peek” at the next iterator with `iterator.next()`. + +This function is used internally by the `async` module, but can be useful when +you want to manually control the flow of functions in series. + +__Arguments__ + +* `tasks` - An array of functions to run. + +__Example__ + +```js +var iterator = async.iterator([ + function(){ sys.p('one'); }, + function(){ sys.p('two'); }, + function(){ sys.p('three'); } +]); + +node> var iterator2 = iterator(); +'one' +node> var iterator3 = iterator2(); +'two' +node> iterator3(); +'three' +node> var nextfn = iterator2.next(); +node> nextfn(); +'three' +``` + +--------------------------------------- + + +### apply(function, arguments..) + +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. + +__Arguments__ + +* `function` - The function you want to eventually apply all arguments to. +* `arguments...` - Any number of arguments to automatically apply when the + continuation is called. + +__Example__ + +```js +// 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: + +```js +node> var fn = async.apply(sys.puts, 'one'); +node> fn('two', 'three'); +one +two +three +``` + +--------------------------------------- + + +### nextTick(callback), setImmediate(callback) + +Calls `callback` on a later loop around the event loop. In Node.js this just +calls `process.nextTick`; in the browser it falls back to `setImmediate(callback)` +if available, otherwise `setTimeout(callback, 0)`, which means other higher priority +events may precede the execution of `callback`. + +This is used internally for browser-compatibility purposes. + +__Arguments__ + +* `callback` - The function to call on a later loop around the event loop. + +__Example__ + +```js +var call_order = []; +async.nextTick(function(){ + call_order.push('two'); + // call_order now equals ['one','two'] +}); +call_order.push('one') +``` + + +### times(n, iterator, [callback]) + +Calls the `iterator` function `n` times, and accumulates results in the same manner +you would use with [`map`](#map). + +__Arguments__ + +* `n` - The number of times to run the function. +* `iterator` - The function to call `n` times. +* `callback` - see [`map`](#map) + +__Example__ + +```js +// Pretend this is some complicated async factory +var createUser = function(id, callback) { + callback(null, { + id: 'user' + id + }) +} +// generate 5 users +async.times(5, function(n, next){ + createUser(n, function(err, user) { + next(err, user) + }) +}, function(err, users) { + // we should now have 5 users +}); +``` + +__Related__ + +* timesSeries(n, iterator, [callback]) +* timesLimit(n, limit, iterator, [callback]) + + +## Utils + + +### memoize(fn, [hasher]) + +Caches the results of an `async` function. When creating a hash to store function +results against, the callback is omitted from the hash and an optional hash +function can be used. + +If no hash function is specified, the first argument is used as a hash key, which may work reasonably if it is a string or a data type that converts to a distinct string. Note that objects and arrays will not behave reasonably. Neither will cases where the other arguments are significant. In such cases, specify your own hash function. + +The cache of results is exposed as the `memo` property of the function returned +by `memoize`. + +__Arguments__ + +* `fn` - The function to proxy and cache results from. +* `hasher` - An optional function for generating a custom hash for storing + results. It has all the arguments applied to it apart from the callback, and + must be synchronous. + +__Example__ + +```js +var slow_fn = function (name, callback) { + // do something + callback(null, result); +}; +var fn = async.memoize(slow_fn); + +// fn can now be used as if it were slow_fn +fn('some name', function () { + // callback +}); +``` + + +### unmemoize(fn) + +Undoes a [`memoize`](#memoize)d function, reverting it to the original, unmemoized +form. Handy for testing. + +__Arguments__ + +* `fn` - the memoized function + +--------------------------------------- + + +### ensureAsync(fn) + +Wrap an async function and ensure it calls its callback on a later tick of the event loop. If the function already calls its callback on a next tick, no extra deferral is added. This is useful for preventing stack overflows (`RangeError: Maximum call stack size exceeded`) and generally keeping [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony) contained. + +__Arguments__ + +* `fn` - an async function, one that expects a node-style callback as its last argument + +Returns a wrapped function with the exact same call signature as the function passed in. + +__Example__ + +```js +function sometimesAsync(arg, callback) { + if (cache[arg]) { + return callback(null, cache[arg]); // this would be synchronous!! + } else { + doSomeIO(arg, callback); // this IO would be asynchronous + } +} + +// this has a risk of stack overflows if many results are cached in a row +async.mapSeries(args, sometimesAsync, done); + +// this will defer sometimesAsync's callback if necessary, +// preventing stack overflows +async.mapSeries(args, async.ensureAsync(sometimesAsync), done); + +``` + +--------------------------------------- + + +### constant(values...) + +Returns a function that when called, calls-back with the values provided. Useful as the first function in a `waterfall`, or for plugging values in to `auto`. + +__Example__ + +```js +async.waterfall([ + async.constant(42), + function (value, next) { + // value === 42 + }, + //... +], callback); + +async.waterfall([ + async.constant(filename, "utf8"), + fs.readFile, + function (fileData, next) { + //... + } + //... +], callback); + +async.auto({ + hostname: async.constant("https://server.net/"), + port: findFreePort, + launchServer: ["hostname", "port", function (cb, options) { + startServer(options, cb); + }], + //... +}, callback); + +``` + +--------------------------------------- + + + +### asyncify(func) + +__Alias:__ `wrapSync` + +Take a sync function and make it async, passing its return value to a callback. This is useful for plugging sync functions into a waterfall, series, or other async functions. Any arguments passed to the generated function will be passed to the wrapped function (except for the final callback argument). Errors thrown will be passed to the callback. + +__Example__ + +```js +async.waterfall([ + async.apply(fs.readFile, filename, "utf8"), + async.asyncify(JSON.parse), + function (data, next) { + // data is the result of parsing the text. + // If there was a parsing error, it would have been caught. + } +], callback) +``` + +--------------------------------------- + + +### log(function, arguments) + +Logs the result of an `async` function to the `console`. Only works in Node.js or +in browsers that support `console.log` and `console.error` (such as FF and Chrome). +If multiple arguments are returned from the async function, `console.log` is +called on each argument in order. + +__Arguments__ + +* `function` - The function you want to eventually apply all arguments to. +* `arguments...` - Any number of arguments to apply to the function. + +__Example__ + +```js +var hello = function(name, callback){ + setTimeout(function(){ + callback(null, 'hello ' + name); + }, 1000); +}; +``` +```js +node> async.log(hello, 'world'); +'hello world' +``` + +--------------------------------------- + + +### dir(function, arguments) + +Logs the result of an `async` function to the `console` using `console.dir` to +display the properties of the resulting object. Only works in Node.js or +in browsers that support `console.dir` and `console.error` (such as FF and Chrome). +If multiple arguments are returned from the async function, `console.dir` is +called on each argument in order. + +__Arguments__ + +* `function` - The function you want to eventually apply all arguments to. +* `arguments...` - Any number of arguments to apply to the function. + +__Example__ + +```js +var hello = function(name, callback){ + setTimeout(function(){ + callback(null, {hello: name}); + }, 1000); +}; +``` +```js +node> async.dir(hello, 'world'); +{hello: 'world'} +``` + +--------------------------------------- + + +### noConflict() + +Changes the value of `async` back to its original value, returning a reference to the +`async` object. diff --git a/build/async.js b/build/async.js index 84513d75e..e5d60e308 100644 --- a/build/async.js +++ b/build/async.js @@ -1,9 +1,30 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : - factory((global.async = {})); + (factory((global.async = {}))); }(this, function (exports) { 'use strict'; + /** + * A faster alternative to `Function#apply`, this function invokes `func` + * with the `this` binding of `thisArg` and the arguments of `args`. + * + * @private + * @param {Function} func The function to invoke. + * @param {*} thisArg The `this` binding of `func`. + * @param {...*} [args] The arguments to invoke `func` with. + * @returns {*} Returns the result of `func`. + */ + function apply$1(func, thisArg, args) { + var length = args ? args.length : 0; + switch (length) { + case 0: return func.call(thisArg); + case 1: return func.call(thisArg, args[0]); + case 2: return func.call(thisArg, args[0], args[1]); + case 3: return func.call(thisArg, args[0], args[1], args[2]); + } + return func.apply(thisArg, args); + } + /** * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) @@ -34,27 +55,6 @@ return !!value && (type == 'object' || type == 'function'); } - /** - * A faster alternative to `Function#apply`, this function invokes `func` - * with the `this` binding of `thisArg` and the arguments of `args`. - * - * @private - * @param {Function} func The function to invoke. - * @param {*} thisArg The `this` binding of `func`. - * @param {...*} [args] The arguments to invoke `func` with. - * @returns {*} Returns the result of `func`. - */ - function apply$1(func, thisArg, args) { - var length = args ? args.length : 0; - switch (length) { - case 0: return func.call(thisArg); - case 1: return func.call(thisArg, args[0]); - case 2: return func.call(thisArg, args[0], args[1]); - case 3: return func.call(thisArg, args[0], args[1], args[2]); - } - return func.apply(thisArg, args); - } - var funcTag = '[object Function]'; var genTag = '[object GeneratorFunction]'; /** Used for built-in method references. */ @@ -241,77 +241,23 @@ }; } - function asyncify(func) { - return rest(function (args) { - var callback = args.pop(); - var result; - try { - result = func.apply(this, args); - } catch (e) { - return callback(e); - } - // if result is Promise object - if (isObject(result) && typeof result.then === 'function') { - result.then(function (value) { - callback(null, value); - })['catch'](function (err) { - callback(err.message ? err : new Error(err)); - }); + function applyEach$1(eachfn) { + return rest(function (fns, args) { + var go = rest(function (args) { + var that = this; + var callback = args.pop(); + return eachfn(fns, function (fn, _, cb) { + fn.apply(that, args.concat([cb])); + }, callback); + }); + if (args.length) { + return go.apply(this, args); } else { - callback(null, result); + return go; } }); } - /** - * A specialized version of `_.map` for arrays without support for iteratee - * shorthands. - * - * @private - * @param {Array} array The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the new mapped array. - */ - function arrayMap(array, iteratee) { - var index = -1, - length = array.length, - result = Array(length); - - while (++index < length) { - result[index] = iteratee(array[index], index, array); - } - return result; - } - - /** - * The base implementation of `_.property` without support for deep paths. - * - * @private - * @param {string} key The key of the property to get. - * @returns {Function} Returns the new function. - */ - function baseProperty(key) { - return function(object) { - return object == null ? undefined : object[key]; - }; - } - - function _filter(eachfn, arr, iterator, callback) { - var results = []; - eachfn(arr, function (x, index, callback) { - iterator(x, function (v) { - if (v) { - results.push({ index: index, value: x }); - } - callback(); - }); - }, function () { - callback(arrayMap(results.sort(function (a, b) { - return a.index - b.index; - }), baseProperty('value'))); - }); - } - /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT$1 = 'Expected a function'; @@ -387,6 +333,19 @@ // No operation performed. } + /** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new function. + */ + function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; + } + /** * Gets the "length" property value of `object`. * @@ -799,6 +758,36 @@ }; } + function eachOf(object, iterator, callback) { + callback = once(callback || noop); + object = object || []; + + var iter = keyIterator(object); + var key, + completed = 0; + + while ((key = iter()) != null) { + completed += 1; + iterator(object[key], key, onlyOnce(done)); + } + + if (completed === 0) callback(null); + + function done(err) { + completed--; + if (err) { + callback(err); + } + // Check key is null in case iterator isn't exhausted + // and done resolved synchronously. + else if (key === null && completed <= 0) { + callback(null); + } + } + } + + var applyEach = applyEach$1(eachOf); + var _setImmediate = typeof setImmediate === 'function' && setImmediate; var _delay; @@ -849,137 +838,126 @@ iterate(); } - function doSeries(fn) { - return function (obj, iterator, callback) { - return fn(eachOfSeries, obj, iterator, callback); - }; - } + var applyEachSeries = applyEach$1(eachOfSeries); - var filterSeries = doSeries(_filter); + var apply = rest(function (fn, args) { + return rest(function (callArgs) { + return fn.apply(null, args.concat(callArgs)); + }); + }); - function _eachOfLimit(limit) { - return function (obj, iterator, callback) { - callback = once(callback || noop); - obj = obj || []; - var nextKey = keyIterator(obj); - if (limit <= 0) { - return callback(null); + function asyncify(func) { + return rest(function (args) { + var callback = args.pop(); + var result; + try { + result = func.apply(this, args); + } catch (e) { + return callback(e); } - var done = false; - var running = 0; - var errored = false; - - (function replenish() { - if (done && running <= 0) { - return callback(null); - } - - while (running < limit && !errored) { - var key = nextKey(); - if (key === null) { - done = true; - if (running <= 0) { - callback(null); - } - return; - } - running += 1; - iterator(obj[key], key, onlyOnce(function (err) { - running -= 1; - if (err) { - callback(err); - errored = true; - } else { - replenish(); - } - })); - } - })(); - }; + // if result is Promise object + if (isObject(result) && typeof result.then === 'function') { + result.then(function (value) { + callback(null, value); + })['catch'](function (err) { + callback(err.message ? err : new Error(err)); + }); + } else { + callback(null, result); + } + }); } - function doParallelLimit(fn) { - return function (obj, limit, iterator, callback) { - return fn(_eachOfLimit(limit), obj, iterator, callback); - }; + /** + * A specialized version of `_.forEach` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ + function arrayEach(array, iteratee) { + var index = -1, + length = array.length; + + while (++index < length) { + if (iteratee(array[index], index, array) === false) { + break; + } + } + return array; } - var filterLimit = doParallelLimit(_filter); - - function eachOf(object, iterator, callback) { - callback = once(callback || noop); - object = object || []; - - var iter = keyIterator(object); - var key, - completed = 0; - - while ((key = iter()) != null) { - completed += 1; - iterator(object[key], key, onlyOnce(done)); - } - - if (completed === 0) callback(null); + /** + * A specialized version of `_.every` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`. + */ + function arrayEvery(array, predicate) { + var index = -1, + length = array.length; - function done(err) { - completed--; - if (err) { - callback(err); - } - // Check key is null in case iterator isn't exhausted - // and done resolved synchronously. - else if (key === null && completed <= 0) { - callback(null); - } + while (++index < length) { + if (!predicate(array[index], index, array)) { + return false; } + } + return true; } - function doParallel(fn) { - return function (obj, iterator, callback) { - return fn(eachOf, obj, iterator, callback); - }; - } - - var filter = doParallel(_filter); - - function reduce(arr, memo, iterator, cb) { - eachOfSeries(arr, function (x, i, cb) { - iterator(memo, x, function (err, v) { - memo = v; - cb(err); - }); - }, function (err) { - cb(err, memo); - }); - } - - var slice = Array.prototype.slice; - - function reduceRight(arr, memo, iterator, cb) { - var reversed = slice.call(arr).reverse(); - reduce(reversed, memo, iterator, cb); - } - - function eachOfLimit(obj, limit, iterator, cb) { - _eachOfLimit(limit)(obj, iterator, cb); - } - - function _withoutIndex(iterator) { - return function (value, index, callback) { - return iterator(value, callback); - }; - } + /** + * Creates a base function for methods like `_.forIn`. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ + function createBaseFor(fromRight) { + return function(object, iteratee, keysFunc) { + var index = -1, + iterable = Object(object), + props = keysFunc(object), + length = props.length; - function eachLimit(arr, limit, iterator, cb) { - return _eachOfLimit(limit)(arr, _withoutIndex(iterator), cb); + while (length--) { + var key = props[fromRight ? length : ++index]; + if (iteratee(iterable[key], key, iterable) === false) { + break; + } + } + return object; + }; } - function eachSeries(arr, iterator, cb) { - return eachOfSeries(arr, _withoutIndex(iterator), cb); - } + /** + * The base implementation of `baseForIn` and `baseForOwn` which iterates + * over `object` properties returned by `keysFunc` invoking `iteratee` for + * each property. Iteratee functions may exit iteration early by explicitly + * returning `false`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ + var baseFor = createBaseFor(); - function each(arr, iterator, cb) { - return eachOf(arr, _withoutIndex(iterator), cb); + /** + * The base implementation of `_.forOwn` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, iteratee) { + return object && baseFor(object, iteratee, keys); } /** @@ -1001,395 +979,274 @@ return value; } - function _createTester(eachfn, check, getResult) { - return function (arr, limit, iterator, cb) { - function done() { - if (cb) cb(getResult(false, void 0)); - } - function iteratee(x, _, callback) { - if (!cb) return callback(); - iterator(x, function (v) { - if (cb && check(v)) { - cb(getResult(true, x)); - cb = iterator = false; - } - callback(); - }); - } - if (arguments.length > 3) { - eachfn(arr, limit, iteratee, done); - } else { - cb = iterator; - iterator = limit; - eachfn(arr, iteratee, done); - } - }; - } - - var some = _createTester(eachOf, Boolean, identity); - - function notId(v) { - return !v; + /** + * Converts `value` to a function if it's not one. + * + * @private + * @param {*} value The value to process. + * @returns {Function} Returns the function. + */ + function toFunction(value) { + return typeof value == 'function' ? value : identity; } - var every = _createTester(eachOf, notId, notId); - - function whilst(test, iterator, cb) { - cb = cb || noop; - if (!test()) return cb(null); - var next = rest(function (err, args) { - if (err) return cb(err); - if (test.apply(this, args)) return iterator(next); - cb.apply(null, [null].concat(args)); - }); - iterator(next); + /** + * Iterates over own enumerable properties of an object invoking `iteratee` + * for each property. The iteratee is invoked with three arguments: + * (value, key, object). Iteratee functions may exit iteration early by + * explicitly returning `false`. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forOwn(new Foo, function(value, key) { + * console.log(key); + * }); + * // => logs 'a' then 'b' (iteration order is not guaranteed) + */ + function forOwn(object, iteratee) { + return object && baseForOwn(object, toFunction(iteratee)); } - function ensureAsync(fn) { - return rest(function (args) { - var callback = args.pop(); - var sync = true; - args.push(function () { - var innerArgs = arguments; - if (sync) { - setImmediate$1(function () { - callback.apply(null, innerArgs); - }); - } else { - callback.apply(null, innerArgs); - } - }); - fn.apply(this, args); - sync = false; - }); - } + /** + * Gets the index at which the first occurrence of `NaN` is found in `array`. + * + * @private + * @param {Array} array The array to search. + * @param {number} fromIndex The index to search from. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched `NaN`, else `-1`. + */ + function indexOfNaN(array, fromIndex, fromRight) { + var length = array.length, + index = fromIndex + (fromRight ? 0 : -1); - function iterator (tasks) { - function makeCallback(index) { - function fn() { - if (tasks.length) { - tasks[index].apply(null, arguments); - } - return fn.next(); - } - fn.next = function () { - return index < tasks.length - 1 ? makeCallback(index + 1) : null; - }; - return fn; + while ((fromRight ? index-- : ++index < length)) { + var other = array[index]; + if (other !== other) { + return index; } - return makeCallback(0); + } + return -1; } - function waterfall (tasks, cb) { - cb = once(cb || noop); - if (!isArray(tasks)) return cb(new Error('First argument to waterfall must be an array of functions')); - if (!tasks.length) return cb(); + /** + * The base implementation of `_.indexOf` without `fromIndex` bounds checks. + * + * @private + * @param {Array} array The array to search. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function baseIndexOf(array, value, fromIndex) { + if (value !== value) { + return indexOfNaN(array, fromIndex); + } + var index = fromIndex - 1, + length = array.length; - function wrapIterator(iterator) { - return rest(function (err, args) { - if (err) { - cb.apply(null, [err].concat(args)); - } else { - var next = iterator.next(); - if (next) { - args.push(wrapIterator(next)); - } else { - args.push(cb); - } - ensureAsync(iterator).apply(null, args); - } - }); + while (++index < length) { + if (array[index] === value) { + return index; } - wrapIterator(iterator(tasks))(); + } + return -1; } - function until(test, iterator, cb) { - return whilst(function () { - return !test.apply(this, arguments); - }, iterator, cb); - } + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeMax$1 = Math.max; - function unmemoize(fn) { - return function () { - return (fn.unmemoized || fn).apply(null, arguments); - }; + /** + * Gets the index at which the first occurrence of `value` is found in `array` + * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it's used as the offset + * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` + * performs a faster binary search. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to search. + * @param {*} value The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.indexOf([1, 2, 1, 2], 2); + * // => 1 + * + * // using `fromIndex` + * _.indexOf([1, 2, 1, 2], 2, 2); + * // => 3 + */ + function indexOf(array, value, fromIndex) { + var length = array ? array.length : 0; + if (!length) { + return -1; + } + fromIndex = toInteger(fromIndex); + if (fromIndex < 0) { + fromIndex = nativeMax$1(length + fromIndex, 0); + } + return baseIndexOf(array, value, fromIndex); } - function transform(arr, memo, iterator, callback) { - if (arguments.length === 3) { - callback = iterator; - iterator = memo; - memo = isArray(arr) ? [] : {}; + function auto (tasks, concurrency, callback) { + if (typeof arguments[1] === 'function') { + // concurrency is optional, shift the args. + callback = concurrency; + concurrency = null; + } + callback = once(callback || noop); + var keys$$ = keys(tasks); + var remainingTasks = keys$$.length; + if (!remainingTasks) { + return callback(null); + } + if (!concurrency) { + concurrency = remainingTasks; } - eachOf(arr, function (v, k, cb) { - iterator(memo, v, k, cb); - }, function (err) { - callback(err, memo); + var results = {}; + var runningTasks = 0; + + var listeners = []; + function addListener(fn) { + listeners.unshift(fn); + } + function removeListener(fn) { + var idx = indexOf(listeners, fn); + if (idx >= 0) listeners.splice(idx, 1); + } + function taskComplete() { + remainingTasks--; + arrayEach(listeners.slice(), function (fn) { + fn(); + }); + } + + addListener(function () { + if (!remainingTasks) { + callback(null, results); + } }); - } - function _asyncMap(eachfn, arr, iterator, callback) { - callback = once(callback || noop); - arr = arr || []; - var results = isArrayLike(arr) ? [] : {}; - eachfn(arr, function (value, index, callback) { - iterator(value, function (err, v) { - results[index] = v; - callback(err); + arrayEach(keys$$, function (k) { + var task = isArray(tasks[k]) ? tasks[k] : [tasks[k]]; + var taskCallback = rest(function (err, args) { + runningTasks--; + if (args.length <= 1) { + args = args[0]; + } + if (err) { + var safeResults = {}; + forOwn(results, function (val, rkey) { + safeResults[rkey] = val; + }); + safeResults[k] = args; + callback(err, safeResults); + } else { + results[k] = args; + setImmediate$1(taskComplete); + } }); - }, function (err) { - callback(err, results); + var requires = task.slice(0, task.length - 1); + // prevent dead-locks + var len = requires.length; + var dep; + while (len--) { + if (!(dep = tasks[requires[len]])) { + throw new Error('Has inexistant dependency'); + } + if (isArray(dep) && indexOf(dep, k) >= 0) { + throw new Error('Has cyclic dependencies'); + } + } + function ready() { + return runningTasks < concurrency && !baseHas(results, k) && arrayEvery(requires, function (x) { + return baseHas(results, x); + }); + } + if (ready()) { + runningTasks++; + task[task.length - 1](taskCallback, results); + } else { + addListener(listener); + } + function listener() { + if (ready()) { + runningTasks++; + removeListener(listener); + task[task.length - 1](taskCallback, results); + } + } }); } - var mapSeries = doSeries(_asyncMap); - - /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeCeil = Math.ceil; - var nativeMax$2 = Math.max; /** - * The base implementation of `_.range` and `_.rangeRight` which doesn't - * coerce arguments to numbers. + * A specialized version of `_.map` for arrays without support for iteratee + * shorthands. * * @private - * @param {number} start The start of the range. - * @param {number} end The end of the range. - * @param {number} step The value to increment or decrement by. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Array} Returns the new array of numbers. + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. */ - function baseRange(start, end, step, fromRight) { + function arrayMap(array, iteratee) { var index = -1, - length = nativeMax$2(nativeCeil((end - start) / (step || 1)), 0), + length = array.length, result = Array(length); - while (length--) { - result[fromRight ? length : ++index] = start; - start += step; + while (++index < length) { + result[index] = iteratee(array[index], index, array); } return result; } - function timesSeries (count, iterator, callback) { - mapSeries(baseRange(0, count, 1), iterator, callback); - } - - var mapLimit = doParallelLimit(_asyncMap); - - function timeLimit(count, limit, iterator, cb) { - return mapLimit(baseRange(0, count, 1), limit, iterator, cb); - } - - var map = doParallel(_asyncMap); + function queue$1(worker, concurrency, payload) { + if (concurrency == null) { + concurrency = 1; + } else if (concurrency === 0) { + throw new Error('Concurrency must not be zero'); + } + function _insert(q, data, pos, callback) { + if (callback != null && typeof callback !== 'function') { + throw new Error('task callback must be a function'); + } + q.started = true; + if (!isArray(data)) { + data = [data]; + } + if (data.length === 0 && q.idle()) { + // call drain immediately if there are no tasks + return setImmediate$1(function () { + q.drain(); + }); + } + arrayEach(data, function (task) { + var item = { + data: task, + callback: callback || noop + }; - function times (count, iterator, callback) { - map(baseRange(0, count, 1), iterator, callback); - } - - function sortBy(arr, iterator, cb) { - map(arr, function (x, cb) { - iterator(x, function (err, criteria) { - if (err) return cb(err); - cb(null, { value: x, criteria: criteria }); - }); - }, function (err, results) { - if (err) return cb(err); - cb(null, arrayMap(results.sort(comparator), baseProperty('value'))); - }); - - function comparator(left, right) { - var a = left.criteria, - b = right.criteria; - return a < b ? -1 : a > b ? 1 : 0; - } - } - - var someLimit = _createTester(eachOfLimit, Boolean, identity); - - function _parallel(eachfn, tasks, callback) { - callback = callback || noop; - var results = isArrayLike(tasks) ? [] : {}; - - eachfn(tasks, function (task, key, callback) { - task(rest(function (err, args) { - if (args.length <= 1) { - args = args[0]; - } - results[key] = args; - callback(err); - })); - }, function (err) { - callback(err, results); - }); - } - - function series(tasks, cb) { - return _parallel(eachOfSeries, tasks, cb); - } - - function seq() /* functions... */{ - var fns = arguments; - return rest(function (args) { - var that = this; - - var cb = args[args.length - 1]; - if (typeof cb == 'function') { - args.pop(); - } else { - cb = noop; - } - - reduce(fns, args, function (newargs, fn, cb) { - fn.apply(that, newargs.concat([rest(function (err, nextargs) { - cb(err, nextargs); - })])); - }, function (err, results) { - cb.apply(that, [err].concat(results)); - }); - }); - } - - function retry(times, task, callback) { - var DEFAULT_TIMES = 5; - var DEFAULT_INTERVAL = 0; - - var attempts = []; - - var opts = { - times: DEFAULT_TIMES, - interval: DEFAULT_INTERVAL - }; - - function parseTimes(acc, t) { - if (typeof t === 'number') { - acc.times = parseInt(t, 10) || DEFAULT_TIMES; - } else if (typeof t === 'object') { - acc.times = parseInt(t.times, 10) || DEFAULT_TIMES; - acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL; - } else { - throw new Error('Unsupported argument type for \'times\': ' + typeof t); - } - } - - var length = arguments.length; - if (length < 1 || length > 3) { - throw new Error('Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)'); - } else if (length <= 2 && typeof times === 'function') { - callback = task; - task = times; - } - if (typeof times !== 'function') { - parseTimes(opts, times); - } - opts.callback = callback; - opts.task = task; - - function wrappedTask(wrappedCallback, wrappedResults) { - function retryAttempt(task, finalAttempt) { - return function (seriesCallback) { - task(function (err, result) { - seriesCallback(!err || finalAttempt, { - err: err, - result: result - }); - }, wrappedResults); - }; - } - - function retryInterval(interval) { - return function (seriesCallback) { - setTimeout(function () { - seriesCallback(null); - }, interval); - }; - } - - while (opts.times) { - - var finalAttempt = !(opts.times -= 1); - attempts.push(retryAttempt(opts.task, finalAttempt)); - if (!finalAttempt && opts.interval > 0) { - attempts.push(retryInterval(opts.interval)); - } - } - - series(attempts, function (done, data) { - data = data[data.length - 1]; - (wrappedCallback || opts.callback)(data.err, data.result); - }); - } - - // If a callback is passed, run this as a controll flow - return opts.callback ? wrappedTask() : wrappedTask; - } - - function reject$1(eachfn, arr, iterator, callback) { - _filter(eachfn, arr, function (value, cb) { - iterator(value, function (v) { - cb(!v); - }); - }, callback); - } - - var rejectSeries = doSeries(reject$1); - - var rejectLimit = doParallelLimit(reject$1); - - var reject = doParallel(reject$1); - - /** - * A specialized version of `_.forEach` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} array The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns `array`. - */ - function arrayEach(array, iteratee) { - var index = -1, - length = array.length; - - while (++index < length) { - if (iteratee(array[index], index, array) === false) { - break; - } - } - return array; - } - - function queue$1(worker, concurrency, payload) { - if (concurrency == null) { - concurrency = 1; - } else if (concurrency === 0) { - throw new Error('Concurrency must not be zero'); - } - function _insert(q, data, pos, callback) { - if (callback != null && typeof callback !== 'function') { - throw new Error('task callback must be a function'); - } - q.started = true; - if (!isArray(data)) { - data = [data]; - } - if (data.length === 0 && q.idle()) { - // call drain immediately if there are no tasks - return setImmediate$1(function () { - q.drain(); - }); - } - arrayEach(data, function (task) { - var item = { - data: task, - callback: callback || noop - }; - - if (pos) { - q.tasks.unshift(item); - } else { - q.tasks.push(item); - } + if (pos) { + q.tasks.unshift(item); + } else { + q.tasks.push(item); + } if (q.tasks.length === q.concurrency) { q.saturated(); @@ -1488,115 +1345,164 @@ return q; } - function queue (worker, concurrency) { - return queue$1(function (items, cb) { - worker(items[0], cb); - }, concurrency, 1); + function cargo(worker, payload) { + return queue$1(worker, 1, payload); } - function priorityQueue (worker, concurrency) { - function _compareTasks(a, b) { - return a.priority - b.priority; - } + function reduce(arr, memo, iterator, cb) { + eachOfSeries(arr, function (x, i, cb) { + iterator(memo, x, function (err, v) { + memo = v; + cb(err); + }); + }, function (err) { + cb(err, memo); + }); + } - function _binarySearch(sequence, item, compare) { - var beg = -1, - end = sequence.length - 1; - while (beg < end) { - var mid = beg + (end - beg + 1 >>> 1); - if (compare(item, sequence[mid]) >= 0) { - beg = mid; - } else { - end = mid - 1; - } - } - return beg; - } + function seq() /* functions... */{ + var fns = arguments; + return rest(function (args) { + var that = this; - function _insert(q, data, priority, callback) { - if (callback != null && typeof callback !== 'function') { - throw new Error('task callback must be a function'); - } - q.started = true; - if (!isArray(data)) { - data = [data]; + var cb = args[args.length - 1]; + if (typeof cb == 'function') { + args.pop(); + } else { + cb = noop; } - if (data.length === 0) { - // call drain immediately if there are no tasks - return setImmediate$1(function () { - q.drain(); - }); - } - arrayEach(data, function (task) { - var item = { - data: task, - priority: priority, - callback: typeof callback === 'function' ? callback : noop - }; - q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item); - - if (q.tasks.length === q.concurrency) { - q.saturated(); - } - setImmediate$1(q.process); + reduce(fns, args, function (newargs, fn, cb) { + fn.apply(that, newargs.concat([rest(function (err, nextargs) { + cb(err, nextargs); + })])); + }, function (err, results) { + cb.apply(that, [err].concat(results)); }); - } - - // Start with a normal queue - var q = queue(worker, concurrency); + }); + } - // Override push to accept second parameter representing priority - q.push = function (data, priority, callback) { - _insert(q, data, priority, callback); - }; + var reverse = Array.prototype.reverse; - // Remove unshift function - delete q.unshift; + function compose() /* functions... */{ + return seq.apply(null, reverse.call(arguments)); + } - return q; + function concat$1(eachfn, arr, fn, callback) { + var result = []; + eachfn(arr, function (x, index, cb) { + fn(x, function (err, y) { + result = result.concat(y || []); + cb(err); + }); + }, function (err) { + callback(err, result); + }); } - function parallelLimit(tasks, limit, cb) { - return _parallel(_eachOfLimit(limit), tasks, cb); + function doParallel(fn) { + return function (obj, iterator, callback) { + return fn(eachOf, obj, iterator, callback); + }; } - function parallel(tasks, cb) { - return _parallel(eachOf, tasks, cb); + var concat = doParallel(concat$1); + + function doSeries(fn) { + return function (obj, iterator, callback) { + return fn(eachOfSeries, obj, iterator, callback); + }; } - var nexTick = typeof process === 'object' && typeof process.nextTick === 'function' ? process.nextTick : setImmediate$1; + var concatSeries = doSeries(concat$1); - function memoize(fn, hasher) { - var memo = {}; - var queues = {}; - hasher = hasher || identity; - var memoized = rest(function memoized(args) { - var callback = args.pop(); - var key = hasher.apply(null, args); - if (key in memo) { - setImmediate$1(function () { - callback.apply(null, memo[key]); + var constant = rest(function (values) { + var args = [null].concat(values); + return function (cb) { + return cb.apply(this, args); + }; + }); + + function _createTester(eachfn, check, getResult) { + return function (arr, limit, iterator, cb) { + function done() { + if (cb) cb(getResult(false, void 0)); + } + function iteratee(x, _, callback) { + if (!cb) return callback(); + iterator(x, function (v) { + if (cb && check(v)) { + cb(getResult(true, x)); + cb = iterator = false; + } + callback(); }); - } else if (key in queues) { - queues[key].push(callback); + } + if (arguments.length > 3) { + eachfn(arr, limit, iteratee, done); } else { - queues[key] = [callback]; - fn.apply(null, args.concat([rest(function (args) { - memo[key] = args; - var q = queues[key]; - delete queues[key]; - for (var i = 0, l = q.length; i < l; i++) { - q[i].apply(null, args); - } - })])); + cb = iterator; + iterator = limit; + eachfn(arr, iteratee, done); } - }); - memoized.memo = memo; - memoized.unmemoized = fn; - return memoized; + }; + } + + function _findGetResult(v, x) { + return x; + } + + var detect = _createTester(eachOf, identity, _findGetResult); + + function _eachOfLimit(limit) { + return function (obj, iterator, callback) { + callback = once(callback || noop); + obj = obj || []; + var nextKey = keyIterator(obj); + if (limit <= 0) { + return callback(null); + } + var done = false; + var running = 0; + var errored = false; + + (function replenish() { + if (done && running <= 0) { + return callback(null); + } + + while (running < limit && !errored) { + var key = nextKey(); + if (key === null) { + done = true; + if (running <= 0) { + callback(null); + } + return; + } + running += 1; + iterator(obj[key], key, onlyOnce(function (err) { + running -= 1; + if (err) { + callback(err); + errored = true; + } else { + replenish(); + } + })); + } + })(); + }; + } + + function eachOfLimit(obj, limit, iterator, cb) { + _eachOfLimit(limit)(obj, iterator, cb); } + var detectLimit = _createTester(eachOfLimit, identity, _findGetResult); + + var detectSeries = _createTester(eachOfSeries, identity, _findGetResult); + function consoleFunc(name) { return rest(function (fn, args) { fn.apply(null, args.concat([rest(function (err, args) { @@ -1615,20 +1521,7 @@ }); } - var log = consoleFunc('log'); - - function forever(fn, cb) { - var done = onlyOnce(cb || noop); - var task = ensureAsync(fn); - - function next(err) { - if (err) return done(err); - task(next); - } - next(); - } - - var everyLimit = _createTester(eachOfLimit, notId, notId); + var dir = consoleFunc('dir'); function during(test, iterator, cb) { cb = cb || noop; @@ -1651,6 +1544,26 @@ test(check); } + function doDuring(iterator, test, cb) { + var calls = 0; + + during(function (next) { + if (calls++ < 1) return next(null, true); + test.apply(this, arguments); + }, iterator, cb); + } + + function whilst(test, iterator, cb) { + cb = cb || noop; + if (!test()) return cb(null); + var next = rest(function (err, args) { + if (err) return cb(err); + if (test.apply(this, args)) return iterator(next); + cb.apply(null, [null].concat(args)); + }); + iterator(next); + } + function doWhilst(iterator, test, cb) { var calls = 0; return whilst(function () { @@ -1664,374 +1577,461 @@ }, cb); } - function doDuring(iterator, test, cb) { - var calls = 0; + function _withoutIndex(iterator) { + return function (value, index, callback) { + return iterator(value, callback); + }; + } - during(function (next) { - if (calls++ < 1) return next(null, true); - test.apply(this, arguments); - }, iterator, cb); + function each(arr, iterator, cb) { + return eachOf(arr, _withoutIndex(iterator), cb); } - var dir = consoleFunc('dir'); + function eachLimit(arr, limit, iterator, cb) { + return _eachOfLimit(limit)(arr, _withoutIndex(iterator), cb); + } - function _findGetResult(v, x) { - return x; + function eachSeries(arr, iterator, cb) { + return eachOfSeries(arr, _withoutIndex(iterator), cb); } - var detectSeries = _createTester(eachOfSeries, identity, _findGetResult); + function ensureAsync(fn) { + return rest(function (args) { + var callback = args.pop(); + var sync = true; + args.push(function () { + var innerArgs = arguments; + if (sync) { + setImmediate$1(function () { + callback.apply(null, innerArgs); + }); + } else { + callback.apply(null, innerArgs); + } + }); + fn.apply(this, args); + sync = false; + }); + } - var detectLimit = _createTester(eachOfLimit, identity, _findGetResult); + function notId(v) { + return !v; + } - var detect = _createTester(eachOf, identity, _findGetResult); + var every = _createTester(eachOf, notId, notId); - var constant = rest(function (values) { - var args = [null].concat(values); - return function (cb) { - return cb.apply(this, args); - }; - }); + var everyLimit = _createTester(eachOfLimit, notId, notId); - function concat$1(eachfn, arr, fn, callback) { - var result = []; - eachfn(arr, function (x, index, cb) { - fn(x, function (err, y) { - result = result.concat(y || []); - cb(err); + function _filter(eachfn, arr, iterator, callback) { + var results = []; + eachfn(arr, function (x, index, callback) { + iterator(x, function (v) { + if (v) { + results.push({ index: index, value: x }); + } + callback(); }); - }, function (err) { - callback(err, result); + }, function () { + callback(arrayMap(results.sort(function (a, b) { + return a.index - b.index; + }), baseProperty('value'))); }); } - var concatSeries = doSeries(concat$1); + var filter = doParallel(_filter); - var concat = doParallel(concat$1); + function doParallelLimit(fn) { + return function (obj, limit, iterator, callback) { + return fn(_eachOfLimit(limit), obj, iterator, callback); + }; + } - var reverse = Array.prototype.reverse; + var filterLimit = doParallelLimit(_filter); - function compose() /* functions... */{ - return seq.apply(null, reverse.call(arguments)); + var filterSeries = doSeries(_filter); + + function forever(fn, cb) { + var done = onlyOnce(cb || noop); + var task = ensureAsync(fn); + + function next(err) { + if (err) return done(err); + task(next); + } + next(); } - function cargo(worker, payload) { - return queue$1(worker, 1, payload); + function iterator (tasks) { + function makeCallback(index) { + function fn() { + if (tasks.length) { + tasks[index].apply(null, arguments); + } + return fn.next(); + } + fn.next = function () { + return index < tasks.length - 1 ? makeCallback(index + 1) : null; + }; + return fn; + } + return makeCallback(0); } - /** - * A specialized version of `_.every` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} array The array to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`. - */ - function arrayEvery(array, predicate) { - var index = -1, - length = array.length; + var log = consoleFunc('log'); - while (++index < length) { - if (!predicate(array[index], index, array)) { - return false; - } - } - return true; + function _asyncMap(eachfn, arr, iterator, callback) { + callback = once(callback || noop); + arr = arr || []; + var results = isArrayLike(arr) ? [] : {}; + eachfn(arr, function (value, index, callback) { + iterator(value, function (err, v) { + results[index] = v; + callback(err); + }); + }, function (err) { + callback(err, results); + }); } - /** - * Creates a base function for methods like `_.forIn`. - * - * @private - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Function} Returns the new base function. - */ - function createBaseFor(fromRight) { - return function(object, iteratee, keysFunc) { - var index = -1, - iterable = Object(object), - props = keysFunc(object), - length = props.length; + var map = doParallel(_asyncMap); - while (length--) { - var key = props[fromRight ? length : ++index]; - if (iteratee(iterable[key], key, iterable) === false) { - break; - } - } - return object; - }; + var mapLimit = doParallelLimit(_asyncMap); + + var mapSeries = doSeries(_asyncMap); + + function memoize(fn, hasher) { + var memo = {}; + var queues = {}; + hasher = hasher || identity; + var memoized = rest(function memoized(args) { + var callback = args.pop(); + var key = hasher.apply(null, args); + if (key in memo) { + setImmediate$1(function () { + callback.apply(null, memo[key]); + }); + } else if (key in queues) { + queues[key].push(callback); + } else { + queues[key] = [callback]; + fn.apply(null, args.concat([rest(function (args) { + memo[key] = args; + var q = queues[key]; + delete queues[key]; + for (var i = 0, l = q.length; i < l; i++) { + q[i].apply(null, args); + } + })])); + } + }); + memoized.memo = memo; + memoized.unmemoized = fn; + return memoized; } - /** - * The base implementation of `baseForIn` and `baseForOwn` which iterates - * over `object` properties returned by `keysFunc` invoking `iteratee` for - * each property. Iteratee functions may exit iteration early by explicitly - * returning `false`. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {Function} keysFunc The function to get the keys of `object`. - * @returns {Object} Returns `object`. - */ - var baseFor = createBaseFor(); + var nexTick = typeof process === 'object' && typeof process.nextTick === 'function' ? process.nextTick : setImmediate$1; - /** - * The base implementation of `_.forOwn` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Object} Returns `object`. - */ - function baseForOwn(object, iteratee) { - return object && baseFor(object, iteratee, keys); + function _parallel(eachfn, tasks, callback) { + callback = callback || noop; + var results = isArrayLike(tasks) ? [] : {}; + + eachfn(tasks, function (task, key, callback) { + task(rest(function (err, args) { + if (args.length <= 1) { + args = args[0]; + } + results[key] = args; + callback(err); + })); + }, function (err) { + callback(err, results); + }); } - /** - * Converts `value` to a function if it's not one. - * - * @private - * @param {*} value The value to process. - * @returns {Function} Returns the function. - */ - function toFunction(value) { - return typeof value == 'function' ? value : identity; + function parallel(tasks, cb) { + return _parallel(eachOf, tasks, cb); } - /** - * Iterates over own enumerable properties of an object invoking `iteratee` - * for each property. The iteratee is invoked with three arguments: - * (value, key, object). Iteratee functions may exit iteration early by - * explicitly returning `false`. - * - * @static - * @memberOf _ - * @category Object - * @param {Object} object The object to iterate over. - * @param {Function} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns `object`. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.forOwn(new Foo, function(value, key) { - * console.log(key); - * }); - * // => logs 'a' then 'b' (iteration order is not guaranteed) - */ - function forOwn(object, iteratee) { - return object && baseForOwn(object, toFunction(iteratee)); + function parallelLimit(tasks, limit, cb) { + return _parallel(_eachOfLimit(limit), tasks, cb); } - /** - * Gets the index at which the first occurrence of `NaN` is found in `array`. - * - * @private - * @param {Array} array The array to search. - * @param {number} fromIndex The index to search from. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {number} Returns the index of the matched `NaN`, else `-1`. - */ - function indexOfNaN(array, fromIndex, fromRight) { - var length = array.length, - index = fromIndex + (fromRight ? 0 : -1); + function queue (worker, concurrency) { + return queue$1(function (items, cb) { + worker(items[0], cb); + }, concurrency, 1); + } - while ((fromRight ? index-- : ++index < length)) { - var other = array[index]; - if (other !== other) { - return index; + function priorityQueue (worker, concurrency) { + function _compareTasks(a, b) { + return a.priority - b.priority; } - } - return -1; - } - /** - * The base implementation of `_.indexOf` without `fromIndex` bounds checks. - * - * @private - * @param {Array} array The array to search. - * @param {*} value The value to search for. - * @param {number} fromIndex The index to search from. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function baseIndexOf(array, value, fromIndex) { - if (value !== value) { - return indexOfNaN(array, fromIndex); - } - var index = fromIndex - 1, - length = array.length; + function _binarySearch(sequence, item, compare) { + var beg = -1, + end = sequence.length - 1; + while (beg < end) { + var mid = beg + (end - beg + 1 >>> 1); + if (compare(item, sequence[mid]) >= 0) { + beg = mid; + } else { + end = mid - 1; + } + } + return beg; + } - while (++index < length) { - if (array[index] === value) { - return index; + function _insert(q, data, priority, callback) { + if (callback != null && typeof callback !== 'function') { + throw new Error('task callback must be a function'); + } + q.started = true; + if (!isArray(data)) { + data = [data]; + } + if (data.length === 0) { + // call drain immediately if there are no tasks + return setImmediate$1(function () { + q.drain(); + }); + } + arrayEach(data, function (task) { + var item = { + data: task, + priority: priority, + callback: typeof callback === 'function' ? callback : noop + }; + + q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item); + + if (q.tasks.length === q.concurrency) { + q.saturated(); + } + setImmediate$1(q.process); + }); } - } - return -1; + + // Start with a normal queue + var q = queue(worker, concurrency); + + // Override push to accept second parameter representing priority + q.push = function (data, priority, callback) { + _insert(q, data, priority, callback); + }; + + // Remove unshift function + delete q.unshift; + + return q; } - /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeMax$1 = Math.max; + var slice = Array.prototype.slice; - /** - * Gets the index at which the first occurrence of `value` is found in `array` - * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) - * for equality comparisons. If `fromIndex` is negative, it's used as the offset - * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` - * performs a faster binary search. - * - * @static - * @memberOf _ - * @category Array - * @param {Array} array The array to search. - * @param {*} value The value to search for. - * @param {number} [fromIndex=0] The index to search from. - * @returns {number} Returns the index of the matched value, else `-1`. - * @example - * - * _.indexOf([1, 2, 1, 2], 2); - * // => 1 - * - * // using `fromIndex` - * _.indexOf([1, 2, 1, 2], 2, 2); - * // => 3 - */ - function indexOf(array, value, fromIndex) { - var length = array ? array.length : 0; - if (!length) { - return -1; - } - fromIndex = toInteger(fromIndex); - if (fromIndex < 0) { - fromIndex = nativeMax$1(length + fromIndex, 0); - } - return baseIndexOf(array, value, fromIndex); + function reduceRight(arr, memo, iterator, cb) { + var reversed = slice.call(arr).reverse(); + reduce(reversed, memo, iterator, cb); } - function auto (tasks, concurrency, callback) { - if (typeof arguments[1] === 'function') { - // concurrency is optional, shift the args. - callback = concurrency; - concurrency = null; - } - callback = once(callback || noop); - var keys$$ = keys(tasks); - var remainingTasks = keys$$.length; - if (!remainingTasks) { - return callback(null); - } - if (!concurrency) { - concurrency = remainingTasks; - } + function reject$1(eachfn, arr, iterator, callback) { + _filter(eachfn, arr, function (value, cb) { + iterator(value, function (v) { + cb(!v); + }); + }, callback); + } - var results = {}; - var runningTasks = 0; + var reject = doParallel(reject$1); - var listeners = []; - function addListener(fn) { - listeners.unshift(fn); + var rejectLimit = doParallelLimit(reject$1); + + var rejectSeries = doSeries(reject$1); + + function series(tasks, cb) { + return _parallel(eachOfSeries, tasks, cb); + } + + function retry(times, task, callback) { + var DEFAULT_TIMES = 5; + var DEFAULT_INTERVAL = 0; + + var attempts = []; + + var opts = { + times: DEFAULT_TIMES, + interval: DEFAULT_INTERVAL + }; + + function parseTimes(acc, t) { + if (typeof t === 'number') { + acc.times = parseInt(t, 10) || DEFAULT_TIMES; + } else if (typeof t === 'object') { + acc.times = parseInt(t.times, 10) || DEFAULT_TIMES; + acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL; + } else { + throw new Error('Unsupported argument type for \'times\': ' + typeof t); + } } - function removeListener(fn) { - var idx = indexOf(listeners, fn); - if (idx >= 0) listeners.splice(idx, 1); + + var length = arguments.length; + if (length < 1 || length > 3) { + throw new Error('Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)'); + } else if (length <= 2 && typeof times === 'function') { + callback = task; + task = times; } - function taskComplete() { - remainingTasks--; - arrayEach(listeners.slice(), function (fn) { - fn(); - }); + if (typeof times !== 'function') { + parseTimes(opts, times); } + opts.callback = callback; + opts.task = task; - addListener(function () { - if (!remainingTasks) { - callback(null, results); + function wrappedTask(wrappedCallback, wrappedResults) { + function retryAttempt(task, finalAttempt) { + return function (seriesCallback) { + task(function (err, result) { + seriesCallback(!err || finalAttempt, { + err: err, + result: result + }); + }, wrappedResults); + }; } - }); - arrayEach(keys$$, function (k) { - var task = isArray(tasks[k]) ? tasks[k] : [tasks[k]]; - var taskCallback = rest(function (err, args) { - runningTasks--; - if (args.length <= 1) { - args = args[0]; - } - if (err) { - var safeResults = {}; - forOwn(results, function (val, rkey) { - safeResults[rkey] = val; - }); - safeResults[k] = args; - callback(err, safeResults); - } else { - results[k] = args; - setImmediate$1(taskComplete); - } - }); - var requires = task.slice(0, task.length - 1); - // prevent dead-locks - var len = requires.length; - var dep; - while (len--) { - if (!(dep = tasks[requires[len]])) { - throw new Error('Has inexistant dependency'); - } - if (isArray(dep) && indexOf(dep, k) >= 0) { - throw new Error('Has cyclic dependencies'); - } - } - function ready() { - return runningTasks < concurrency && !baseHas(results, k) && arrayEvery(requires, function (x) { - return baseHas(results, x); - }); - } - if (ready()) { - runningTasks++; - task[task.length - 1](taskCallback, results); - } else { - addListener(listener); + function retryInterval(interval) { + return function (seriesCallback) { + setTimeout(function () { + seriesCallback(null); + }, interval); + }; } - function listener() { - if (ready()) { - runningTasks++; - removeListener(listener); - task[task.length - 1](taskCallback, results); + + while (opts.times) { + + var finalAttempt = !(opts.times -= 1); + attempts.push(retryAttempt(opts.task, finalAttempt)); + if (!finalAttempt && opts.interval > 0) { + attempts.push(retryInterval(opts.interval)); } } - }); + + series(attempts, function (done, data) { + data = data[data.length - 1]; + (wrappedCallback || opts.callback)(data.err, data.result); + }); + } + + // If a callback is passed, run this as a controll flow + return opts.callback ? wrappedTask() : wrappedTask; } - var apply = rest(function (fn, args) { - return rest(function (callArgs) { - return fn.apply(null, args.concat(callArgs)); - }); - }); + var some = _createTester(eachOf, Boolean, identity); - function applyEach$1(eachfn) { - return rest(function (fns, args) { - var go = rest(function (args) { - var that = this; - var callback = args.pop(); - return eachfn(fns, function (fn, _, cb) { - fn.apply(that, args.concat([cb])); - }, callback); + var someLimit = _createTester(eachOfLimit, Boolean, identity); + + function sortBy(arr, iterator, cb) { + map(arr, function (x, cb) { + iterator(x, function (err, criteria) { + if (err) return cb(err); + cb(null, { value: x, criteria: criteria }); }); - if (args.length) { - return go.apply(this, args); - } else { - return go; - } + }, function (err, results) { + if (err) return cb(err); + cb(null, arrayMap(results.sort(comparator), baseProperty('value'))); }); + + function comparator(left, right) { + var a = left.criteria, + b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + } } - var applyEachSeries = applyEach$1(eachOfSeries); + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeCeil = Math.ceil; + var nativeMax$2 = Math.max; + /** + * The base implementation of `_.range` and `_.rangeRight` which doesn't + * coerce arguments to numbers. + * + * @private + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @param {number} step The value to increment or decrement by. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the new array of numbers. + */ + function baseRange(start, end, step, fromRight) { + var index = -1, + length = nativeMax$2(nativeCeil((end - start) / (step || 1)), 0), + result = Array(length); - var applyEach = applyEach$1(eachOf); + while (length--) { + result[fromRight ? length : ++index] = start; + start += step; + } + return result; + } + + function times (count, iterator, callback) { + map(baseRange(0, count, 1), iterator, callback); + } + + function timeLimit(count, limit, iterator, cb) { + return mapLimit(baseRange(0, count, 1), limit, iterator, cb); + } + + function timesSeries (count, iterator, callback) { + mapSeries(baseRange(0, count, 1), iterator, callback); + } + + function transform(arr, memo, iterator, callback) { + if (arguments.length === 3) { + callback = iterator; + iterator = memo; + memo = isArray(arr) ? [] : {}; + } + + eachOf(arr, function (v, k, cb) { + iterator(memo, v, k, cb); + }, function (err) { + callback(err, memo); + }); + } + + function unmemoize(fn) { + return function () { + return (fn.unmemoized || fn).apply(null, arguments); + }; + } + + function until(test, iterator, cb) { + return whilst(function () { + return !test.apply(this, arguments); + }, iterator, cb); + } + + function waterfall (tasks, cb) { + cb = once(cb || noop); + if (!isArray(tasks)) return cb(new Error('First argument to waterfall must be an array of functions')); + if (!tasks.length) return cb(); + + function wrapIterator(iterator) { + return rest(function (err, args) { + if (err) { + cb.apply(null, [err].concat(args)); + } else { + var next = iterator.next(); + if (next) { + args.push(wrapIterator(next)); + } else { + args.push(cb); + } + ensureAsync(iterator).apply(null, args); + } + }); + } + wrapIterator(iterator(tasks))(); + } var index = { applyEach: applyEach, diff --git a/build/async.min.js b/build/async.min.js index 9eb834601..ff40154df 100644 --- a/build/async.min.js +++ b/build/async.min.js @@ -1,2 +1,2 @@ -!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.async={})}(this,function(n){"use strict";function t(n){var t=typeof n;return!!n&&("object"==t||"function"==t)}function r(n,t,r){var e=r?r.length:0;switch(e){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function e(n){var r=t(n)?Hn.call(n):"";return r==Un||r==Cn}function u(n){if(t(n)){var r=e(n.valueOf)?n.valueOf():n;n=t(r)?r+"":r}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(Qn,"");var u=Wn.test(n);return u||Gn.test(n)?Jn(n.slice(2),u?2:8):Rn.test(n)?Nn:+n}function i(n){if(!n)return 0===n?n:0;if(n=u(n),n===Kn||n===-Kn){var t=0>n?-1:1;return t*Vn}var r=n%1;return n===n?r?n-r:n:0}function o(n,t){if("function"!=typeof n)throw new TypeError(Xn);return t=Yn(void 0===t?n.length-1:i(t),0),function(){for(var e=arguments,u=-1,i=Yn(e.length-t,0),o=Array(i);++u0&&(r=t.apply(this,arguments)),1>=n&&(t=void 0),r}}function p(n){return s(2,n)}function h(){}function y(n){return"number"==typeof n&&n>-1&&n%1==0&&nt>=n}function m(n){return null!=n&&!("function"==typeof n&&e(n))&&y(_n(n))}function v(n,t){return rt.call(n,t)||"object"==typeof n&&t in n&&null===et(n)}function d(n){return ut(Object(n))}function g(n,t){for(var r=-1,e=Array(n);++r-1&&n%1==0&&t>n}function L(n){var t=n&&n.constructor,r="function"==typeof t&&t.prototype||vt;return n===r}function O(n){var t=L(n);if(!t&&!m(n))return d(n);var r=S(n),e=!!r,u=r||[],i=u.length;for(var o in n)!v(n,o)||e&&("length"==o||j(o,i))||t&&"constructor"==o||u.push(o);return u}function x(n){var t,r=-1;if(m(n))return t=n.length,function(){return r++,t>r?r:null};var e=O(n);return t=e.length,function(){return r++,t>r?e[r]:null}}function A(n){return function(){if(null===n)throw new Error("Callback was already called.");n.apply(this,arguments),n=null}}function I(n,t,r){function e(){var o=!0;return null===i?r(null):(t(n[i],i,A(function(n){if(n)r(n);else{if(i=u(),null===i)return r(null);o?gt(e):e()}})),void(o=!1))}r=p(r||h),n=n||[];var u=x(n),i=u();e()}function T(n){return function(t,r,e){return n(I,t,r,e)}}function z(n){return function(t,r,e){e=p(e||h),t=t||[];var u=x(t);if(0>=n)return e(null);var i=!1,o=0,c=!1;!function a(){if(i&&0>=o)return e(null);for(;n>o&&!c;){var f=u();if(null===f)return i=!0,void(0>=o&&e(null));o+=1,r(t[f],f,A(function(n){o-=1,n?(e(n),c=!0):a()}))}}()}}function M(n){return function(t,r,e,u){return n(z(r),t,e,u)}}function $(n,t,r){function e(n){o--,n?r(n):null===u&&0>=o&&r(null)}r=p(r||h),n=n||[];for(var u,i=x(n),o=0;null!=(u=i());)o+=1,t(n[u],u,A(e));0===o&&r(null)}function q(n){return function(t,r,e){return n($,t,r,e)}}function B(n,t,r,e){I(n,function(n,e,u){r(t,n,function(n,r){t=r,u(n)})},function(n){e(n,t)})}function F(n,t,r,e){var u=Et.call(n).reverse();B(u,t,r,e)}function P(n,t,r,e){z(t)(n,r,e)}function U(n){return function(t,r,e){return n(t,e)}}function C(n,t,r,e){return z(t)(n,U(r),e)}function D(n,t,r){return I(n,U(t),r)}function H(n,t,r){return $(n,U(t),r)}function N(n){return n}function Q(n,t,r){return function(e,u,i,o){function c(){o&&o(r(!1,void 0))}function a(n,e,u){return o?void i(n,function(e){o&&t(e)&&(o(r(!0,n)),o=i=!1),u()}):u()}arguments.length>3?n(e,u,a,c):(o=i,i=u,n(e,a,c))}}function R(n){return!n}function W(n,t,r){if(r=r||h,!n())return r(null);var e=o(function(u,i){return u?r(u):n.apply(this,i)?t(e):void r.apply(null,[null].concat(i))});t(e)}function G(n){return o(function(t){var r=t.pop(),e=!0;t.push(function(){var n=arguments;e?gt(function(){r.apply(null,n)}):r.apply(null,n)}),n.apply(this,t),e=!1})}function J(n){function t(r){function e(){return n.length&&n[r].apply(null,arguments),e.next()}return e.next=function(){return rr?-1:r>e?1:0}It(n,function(n,r){t(n,function(t,e){return t?r(t):void r(null,{value:n,criteria:e})})},function(n,t){return n?r(n):void r(null,a(t.sort(e),f("value")))})}function un(n,t,r){r=r||h;var e=m(t)?[]:{};n(t,function(n,t,r){n(o(function(n,u){u.length<=1&&(u=u[0]),e[t]=u,r(n)}))},function(n){r(n,e)})}function on(n,t){return un(I,n,t)}function cn(){var n=arguments;return o(function(t){var r=this,e=t[t.length-1];"function"==typeof e?t.pop():e=h,B(n,t,function(n,t,e){t.apply(r,n.concat([o(function(n,t){e(n,t)})]))},function(n,t){e.apply(r,[n].concat(t))})})}function an(n,t,r){function e(n,t){if("number"==typeof t)n.times=parseInt(t,10)||i;else{if("object"!=typeof t)throw new Error("Unsupported argument type for 'times': "+typeof t);n.times=parseInt(t.times,10)||i,n.interval=parseInt(t.interval,10)||o}}function u(n,t){function r(n,r){return function(e){n(function(n,t){e(!n||r,{err:n,result:t})},t)}}function e(n){return function(t){setTimeout(function(){t(null)},n)}}for(;a.times;){var u=!(a.times-=1);c.push(r(a.task,u)),!u&&a.interval>0&&c.push(e(a.interval))}on(c,function(t,r){r=r[r.length-1],(n||a.callback)(r.err,r.result)})}var i=5,o=0,c=[],a={times:i,interval:o},f=arguments.length;if(1>f||f>3)throw new Error("Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)");return 2>=f&&"function"==typeof n&&(r=t,t=n),"function"!=typeof n&&e(a,n),a.callback=r,a.task=t,a.callback?u():u}function fn(n,t,r,e){l(n,t,function(n,t){r(n,function(n){t(!n)})},e)}function ln(n,t){for(var r=-1,e=n.length;++r=t;t++)gt(c.process)}}};return c}function pn(n,t){return sn(function(t,r){n(t[0],r)},t,1)}function hn(n,t){function r(n,t){return n.priority-t.priority}function e(n,t,r){for(var e=-1,u=n.length-1;u>e;){var i=e+(u-e+1>>>1);r(t,n[i])>=0?e=i:u=i-1}return e}function u(n,t,u,i){if(null!=i&&"function"!=typeof i)throw new Error("task callback must be a function");return n.started=!0,lt(t)||(t=[t]),0===t.length?gt(function(){n.drain()}):void ln(t,function(t){var o={data:t,priority:u,callback:"function"==typeof i?i:h};n.tasks.splice(e(n.tasks,o,r)+1,0,o),n.tasks.length===n.concurrency&&n.saturated(),gt(n.process)})}var i=pn(n,t);return i.push=function(n,t,r){u(i,n,t,r)},delete i.unshift,i}function yn(n,t,r){return un(z(t),n,r)}function mn(n,t){return un($,n,t)}function vn(n,t){var r={},e={};t=t||N;var u=o(function(u){var i=u.pop(),c=t.apply(null,u);c in r?gt(function(){i.apply(null,r[c])}):c in e?e[c].push(i):(e[c]=[i],n.apply(null,u.concat([o(function(n){r[c]=n;var t=e[c];delete e[c];for(var u=0,i=t.length;i>u;u++)t[u].apply(null,n)})])))});return u.memo=r,u.unmemoized=n,u}function dn(n){return o(function(t,r){t.apply(null,r.concat([o(function(t,r){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&ln(r,function(t){console[n](t)}))})]))})}function gn(n,t){function r(n){return n?e(n):void u(r)}var e=A(t||h),u=G(n);r()}function kn(n,t,r){r=r||h;var e=o(function(t,e){t?r(t):(e.push(u),n.apply(this,e))}),u=function(n,u){return n?r(n):u?void t(e):r(null)};n(u)}function bn(n,t,r){var e=0;return W(function(){return++e<=1||t.apply(this,arguments)},n,r)}function wn(n,t,r){return bn(n,function(){return!t.apply(this,arguments)},r)}function En(n,t,r){var e=0;kn(function(n){return e++<1?n(null,!0):void t.apply(this,arguments)},n,r)}function Sn(n,t){return t}function jn(n,t,r,e){var u=[];n(t,function(n,t,e){r(n,function(n,t){u=u.concat(t||[]),e(n)})},function(n){e(n,u)})}function Ln(){return cn.apply(null,Rt.call(arguments))}function On(n,t){return sn(n,1,t)}function xn(n,t){for(var r=-1,e=n.length;++rr&&(r=Gt(e+r,0)),$n(n,t,r)):-1}function Bn(n,t,r){function e(n){s.unshift(n)}function u(n){var t=qn(s,n);t>=0&&s.splice(t,1)}function i(){a--,ln(s.slice(),function(n){n()})}"function"==typeof arguments[1]&&(r=t,t=null),r=p(r||h);var c=O(n),a=c.length;if(!a)return r(null);t||(t=a);var f={},l=0,s=[];e(function(){a||r(null,f)}),ln(c,function(c){function a(){return t>l&&!v(f,c)&&xn(m,function(n){return v(f,n)})}function s(){a()&&(l++,u(s),h[h.length-1](y,f))}for(var p,h=lt(n[c])?n[c]:[n[c]],y=o(function(n,t){if(l--,t.length<=1&&(t=t[0]),n){var e={};zn(f,function(n,t){e[t]=n}),e[c]=t,r(n,e)}else f[c]=t,gt(i)}),m=h.slice(0,h.length-1),d=m.length;d--;){if(!(p=n[m[d]]))throw new Error("Has inexistant dependency");if(lt(p)&&qn(p,c)>=0)throw new Error("Has cyclic dependencies")}a()?(l++,h[h.length-1](y,f)):e(s)})}function Fn(n){return o(function(t,r){var e=o(function(r){var e=this,u=r.pop();return n(t,function(n,t,u){n.apply(e,r.concat([u]))},u)});return r.length?e.apply(this,r):e})}var Pn,Un="[object Function]",Cn="[object GeneratorFunction]",Dn=Object.prototype,Hn=Dn.toString,Nn=NaN,Qn=/^\s+|\s+$/g,Rn=/^[-+]0x[0-9a-f]+$/i,Wn=/^0b[01]+$/i,Gn=/^0o[0-7]+$/i,Jn=parseInt,Kn=1/0,Vn=1.7976931348623157e308,Xn="Expected a function",Yn=Math.max,Zn="Expected a function",_n=f("length"),nt=9007199254740991,tt=Object.prototype,rt=tt.hasOwnProperty,et=Object.getPrototypeOf,ut=Object.keys,it="[object Arguments]",ot=Object.prototype,ct=ot.hasOwnProperty,at=ot.toString,ft=ot.propertyIsEnumerable,lt=Array.isArray,st="[object String]",pt=Object.prototype,ht=pt.toString,yt=9007199254740991,mt=/^(?:0|[1-9]\d*)$/,vt=Object.prototype,dt="function"==typeof setImmediate&&setImmediate;Pn=dt?function(n){dt(n)}:"object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:function(n){setTimeout(n,0)};var gt=Pn,kt=T(l),bt=M(l),wt=q(l),Et=Array.prototype.slice,St=Q($,Boolean,N),jt=Q($,R,R),Lt=T(Z),Ot=Math.ceil,xt=Math.max,At=M(Z),It=q(Z),Tt=Q(P,Boolean,N),zt=T(fn),Mt=M(fn),$t=q(fn),qt="object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:gt,Bt=dn("log"),Ft=Q(P,R,R),Pt=dn("dir"),Ut=Q(I,N,Sn),Ct=Q(P,N,Sn),Dt=Q($,N,Sn),Ht=o(function(n){var t=[null].concat(n);return function(n){return n.apply(this,t)}}),Nt=T(jn),Qt=q(jn),Rt=Array.prototype.reverse,Wt=An(),Gt=Math.max,Jt=o(function(n,t){return o(function(r){return n.apply(null,t.concat(r))})}),Kt=Fn(I),Vt=Fn($),Xt={applyEach:Vt,applyEachSeries:Kt,apply:Jt,asyncify:c,auto:Bn,cargo:On,compose:Ln,concat:Qt,concatSeries:Nt,constant:Ht,detect:Dt,detectLimit:Ct,detectSeries:Ut,dir:Pt,doDuring:En,doUntil:wn,doWhilst:bn,during:kn,each:H,eachLimit:C,eachOf:$,eachOfLimit:P,eachOfSeries:I,eachSeries:D,ensureAsync:G,every:jt,everyLimit:Ft,filter:wt,filterLimit:bt,filterSeries:kt,forever:gn,iterator:J,log:Bt,map:It,mapLimit:At,mapSeries:Lt,memoize:vn,nextTick:qt,parallel:mn,parallelLimit:yn,priorityQueue:hn,queue:pn,reduce:B,reduceRight:F,reject:$t,rejectLimit:Mt,rejectSeries:zt,retry:an,seq:cn,series:on,setImmediate:gt,some:St,someLimit:Tt,sortBy:en,times:rn,timesLimit:tn,timesSeries:nn,transform:Y,unmemoize:X,until:V,waterfall:K,whilst:W,all:jt,any:St,forEach:H,forEachSeries:D,forEachLimit:C,forEachOf:$,forEachOfSeries:I,forEachOfLimit:P,inject:B,foldl:B,foldr:F,select:wt,selectLimit:bt,selectSeries:kt,wrapSync:c};n["default"]=Xt,n.applyEach=Vt,n.applyEachSeries=Kt,n.apply=Jt,n.asyncify=c,n.auto=Bn,n.cargo=On,n.compose=Ln,n.concat=Qt,n.concatSeries=Nt,n.constant=Ht,n.detect=Dt,n.detectLimit=Ct,n.detectSeries=Ut,n.dir=Pt,n.doDuring=En,n.doUntil=wn,n.doWhilst=bn,n.during=kn,n.each=H,n.eachLimit=C,n.eachOf=$,n.eachOfLimit=P,n.eachOfSeries=I,n.eachSeries=D,n.ensureAsync=G,n.every=jt,n.everyLimit=Ft,n.filter=wt,n.filterLimit=bt,n.filterSeries=kt,n.forever=gn,n.iterator=J,n.log=Bt,n.map=It,n.mapLimit=At,n.mapSeries=Lt,n.memoize=vn,n.nextTick=qt,n.parallel=mn,n.parallelLimit=yn,n.priorityQueue=hn,n.queue=pn,n.reduce=B,n.reduceRight=F,n.reject=$t,n.rejectLimit=Mt,n.rejectSeries=zt,n.retry=an,n.seq=cn,n.series=on,n.setImmediate=gt,n.some=St,n.someLimit=Tt,n.sortBy=en,n.times=rn,n.timesLimit=tn,n.timesSeries=nn,n.transform=Y,n.unmemoize=X,n.until=V,n.waterfall=K,n.whilst=W,n.all=jt,n.any=St,n.forEach=H,n.forEachSeries=D,n.forEachLimit=C,n.forEachOf=$,n.forEachOfSeries=I,n.forEachOfLimit=P,n.inject=B,n.foldl=B,n.foldr=F,n.select=wt,n.selectLimit=bt,n.selectSeries=kt,n.wrapSync=c}); +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.async={})}(this,function(n){"use strict";function t(n,t,r){var e=r?r.length:0;switch(e){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function r(n){var t=typeof n;return!!n&&("object"==t||"function"==t)}function e(n){var t=r(n)?Hn.call(n):"";return t==Un||t==Cn}function u(n){if(r(n)){var t=e(n.valueOf)?n.valueOf():n;n=r(t)?t+"":t}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(Qn,"");var u=Wn.test(n);return u||Gn.test(n)?Jn(n.slice(2),u?2:8):Rn.test(n)?Nn:+n}function i(n){if(!n)return 0===n?n:0;if(n=u(n),n===Kn||n===-Kn){var t=0>n?-1:1;return t*Vn}var r=n%1;return n===n?r?n-r:n:0}function o(n,r){if("function"!=typeof n)throw new TypeError(Xn);return r=Yn(void 0===r?n.length-1:i(r),0),function(){for(var e=arguments,u=-1,i=Yn(e.length-r,0),o=Array(i);++u0&&(r=t.apply(this,arguments)),1>=n&&(t=void 0),r}}function f(n){return a(2,n)}function l(){}function s(n){return function(t){return null==t?void 0:t[n]}}function p(n){return"number"==typeof n&&n>-1&&n%1==0&&nt>=n}function h(n){return null!=n&&!("function"==typeof n&&e(n))&&p(_n(n))}function y(n,t){return rt.call(n,t)||"object"==typeof n&&t in n&&null===et(n)}function m(n){return ut(Object(n))}function v(n,t){for(var r=-1,e=Array(n);++r-1&&n%1==0&&t>n}function S(n){var t=n&&n.constructor,r="function"==typeof t&&t.prototype||vt;return n===r}function j(n){var t=S(n);if(!t&&!h(n))return m(n);var r=w(n),e=!!r,u=r||[],i=u.length;for(var o in n)!y(n,o)||e&&("length"==o||E(o,i))||t&&"constructor"==o||u.push(o);return u}function L(n){var t,r=-1;if(h(n))return t=n.length,function(){return r++,t>r?r:null};var e=j(n);return t=e.length,function(){return r++,t>r?e[r]:null}}function O(n){return function(){if(null===n)throw new Error("Callback was already called.");n.apply(this,arguments),n=null}}function x(n,t,r){function e(n){o--,n?r(n):null===u&&0>=o&&r(null)}r=f(r||l),n=n||[];for(var u,i=L(n),o=0;null!=(u=i());)o+=1,t(n[u],u,O(e));0===o&&r(null)}function A(n,t,r){function e(){var o=!0;return null===i?r(null):(t(n[i],i,O(function(n){if(n)r(n);else{if(i=u(),null===i)return r(null);o?kt(e):e()}})),void(o=!1))}r=f(r||l),n=n||[];var u=L(n),i=u();e()}function I(n){return o(function(t){var e,u=t.pop();try{e=n.apply(this,t)}catch(i){return u(i)}r(e)&&"function"==typeof e.then?e.then(function(n){u(null,n)})["catch"](function(n){u(n.message?n:new Error(n))}):u(null,e)})}function T(n,t){for(var r=-1,e=n.length;++rr&&(r=St(e+r,0)),U(n,t,r)):-1}function D(n,t,r){function e(n){h.unshift(n)}function u(n){var t=C(h,n);t>=0&&h.splice(t,1)}function i(){a--,T(h.slice(),function(n){n()})}"function"==typeof arguments[1]&&(r=t,t=null),r=f(r||l);var c=j(n),a=c.length;if(!a)return r(null);t||(t=a);var s={},p=0,h=[];e(function(){a||r(null,s)}),T(c,function(c){function a(){return t>p&&!y(s,c)&&z(v,function(n){return y(s,n)})}function f(){a()&&(p++,u(f),h[h.length-1](m,s))}for(var l,h=lt(n[c])?n[c]:[n[c]],m=o(function(n,t){if(p--,t.length<=1&&(t=t[0]),n){var e={};F(s,function(n,t){e[t]=n}),e[c]=t,r(n,e)}else s[c]=t,kt(i)}),v=h.slice(0,h.length-1),d=v.length;d--;){if(!(l=n[v[d]]))throw new Error("Has inexistant dependency");if(lt(l)&&C(l,c)>=0)throw new Error("Has cyclic dependencies")}a()?(p++,h[h.length-1](m,s)):e(f)})}function H(n,t){for(var r=-1,e=n.length,u=Array(e);++r=t;t++)kt(c.process)}}};return c}function Q(n,t){return N(n,1,t)}function R(n,t,r,e){A(n,function(n,e,u){r(t,n,function(n,r){t=r,u(n)})},function(n){e(n,t)})}function W(){var n=arguments;return o(function(t){var r=this,e=t[t.length-1];"function"==typeof e?t.pop():e=l,R(n,t,function(n,t,e){t.apply(r,n.concat([o(function(n,t){e(n,t)})]))},function(n,t){e.apply(r,[n].concat(t))})})}function G(){return W.apply(null,jt.call(arguments))}function J(n,t,r,e){var u=[];n(t,function(n,t,e){r(n,function(n,t){u=u.concat(t||[]),e(n)})},function(n){e(n,u)})}function K(n){return function(t,r,e){return n(x,t,r,e)}}function V(n){return function(t,r,e){return n(A,t,r,e)}}function X(n,t,r){return function(e,u,i,o){function c(){o&&o(r(!1,void 0))}function a(n,e,u){return o?void i(n,function(e){o&&t(e)&&(o(r(!0,n)),o=i=!1),u()}):u()}arguments.length>3?n(e,u,a,c):(o=i,i=u,n(e,a,c))}}function Y(n,t){return t}function Z(n){return function(t,r,e){e=f(e||l),t=t||[];var u=L(t);if(0>=n)return e(null);var i=!1,o=0,c=!1;!function a(){if(i&&0>=o)return e(null);for(;n>o&&!c;){var f=u();if(null===f)return i=!0,void(0>=o&&e(null));o+=1,r(t[f],f,O(function(n){o-=1,n?(e(n),c=!0):a()}))}}()}}function _(n,t,r,e){Z(t)(n,r,e)}function nn(n){return o(function(t,r){t.apply(null,r.concat([o(function(t,r){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&T(r,function(t){console[n](t)}))})]))})}function tn(n,t,r){r=r||l;var e=o(function(t,e){t?r(t):(e.push(u),n.apply(this,e))}),u=function(n,u){return n?r(n):u?void t(e):r(null)};n(u)}function rn(n,t,r){var e=0;tn(function(n){return e++<1?n(null,!0):void t.apply(this,arguments)},n,r)}function en(n,t,r){if(r=r||l,!n())return r(null);var e=o(function(u,i){return u?r(u):n.apply(this,i)?t(e):void r.apply(null,[null].concat(i))});t(e)}function un(n,t,r){var e=0;return en(function(){return++e<=1||t.apply(this,arguments)},n,r)}function on(n,t,r){return un(n,function(){return!t.apply(this,arguments)},r)}function cn(n){return function(t,r,e){return n(t,e)}}function an(n,t,r){return x(n,cn(t),r)}function fn(n,t,r,e){return Z(t)(n,cn(r),e)}function ln(n,t,r){return A(n,cn(t),r)}function sn(n){return o(function(t){var r=t.pop(),e=!0;t.push(function(){var n=arguments;e?kt(function(){r.apply(null,n)}):r.apply(null,n)}),n.apply(this,t),e=!1})}function pn(n){return!n}function hn(n,t,r,e){var u=[];n(t,function(n,t,e){r(n,function(r){r&&u.push({index:t,value:n}),e()})},function(){e(H(u.sort(function(n,t){return n.index-t.index}),s("value")))})}function yn(n){return function(t,r,e,u){return n(Z(r),t,e,u)}}function mn(n,t){function r(n){return n?e(n):void u(r)}var e=O(t||l),u=sn(n);r()}function vn(n){function t(r){function e(){return n.length&&n[r].apply(null,arguments),e.next()}return e.next=function(){return ru;u++)t[u].apply(null,n)})])))});return u.memo=r,u.unmemoized=n,u}function kn(n,t,r){r=r||l;var e=h(t)?[]:{};n(t,function(n,t,r){n(o(function(n,u){u.length<=1&&(u=u[0]),e[t]=u,r(n)}))},function(n){r(n,e)})}function bn(n,t){return kn(x,n,t)}function wn(n,t,r){return kn(Z(t),n,r)}function En(n,t){return N(function(t,r){n(t[0],r)},t,1)}function Sn(n,t){function r(n,t){return n.priority-t.priority}function e(n,t,r){for(var e=-1,u=n.length-1;u>e;){var i=e+(u-e+1>>>1);r(t,n[i])>=0?e=i:u=i-1}return e}function u(n,t,u,i){if(null!=i&&"function"!=typeof i)throw new Error("task callback must be a function");return n.started=!0,lt(t)||(t=[t]),0===t.length?kt(function(){n.drain()}):void T(t,function(t){var o={data:t,priority:u,callback:"function"==typeof i?i:l};n.tasks.splice(e(n.tasks,o,r)+1,0,o),n.tasks.length===n.concurrency&&n.saturated(),kt(n.process)})}var i=En(n,t);return i.push=function(n,t,r){u(i,n,t,r)},delete i.unshift,i}function jn(n,t,r,e){var u=Nt.call(n).reverse();R(u,t,r,e)}function Ln(n,t,r,e){hn(n,t,function(n,t){r(n,function(n){t(!n)})},e)}function On(n,t){return kn(A,n,t)}function xn(n,t,r){function e(n,t){if("number"==typeof t)n.times=parseInt(t,10)||i;else{if("object"!=typeof t)throw new Error("Unsupported argument type for 'times': "+typeof t);n.times=parseInt(t.times,10)||i,n.interval=parseInt(t.interval,10)||o}}function u(n,t){function r(n,r){return function(e){n(function(n,t){e(!n||r,{err:n,result:t})},t)}}function e(n){return function(t){setTimeout(function(){t(null)},n)}}for(;a.times;){var u=!(a.times-=1);c.push(r(a.task,u)),!u&&a.interval>0&&c.push(e(a.interval))}On(c,function(t,r){r=r[r.length-1],(n||a.callback)(r.err,r.result)})}var i=5,o=0,c=[],a={times:i,interval:o},f=arguments.length;if(1>f||f>3)throw new Error("Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)");return 2>=f&&"function"==typeof n&&(r=t,t=n),"function"!=typeof n&&e(a,n),a.callback=r,a.task=t,a.callback?u():u}function An(n,t,r){function e(n,t){var r=n.criteria,e=t.criteria;return e>r?-1:r>e?1:0}Ut(n,function(n,r){t(n,function(t,e){return t?r(t):void r(null,{value:n,criteria:e})})},function(n,t){return n?r(n):void r(null,H(t.sort(e),s("value")))})}function In(n,t,r,e){for(var u=-1,i=Vt(Kt((t-n)/(r||1)),0),o=Array(i);i--;)o[e?i:++u]=n,n+=r;return o}function Tn(n,t,r){Ut(In(0,n,1),t,r)}function zn(n,t,r,e){return Ct(In(0,n,1),t,r,e)}function Mn(n,t,r){Dt(In(0,n,1),t,r)}function $n(n,t,r,e){3===arguments.length&&(e=r,r=t,t=lt(n)?[]:{}),x(n,function(n,e,u){r(t,n,e,u)},function(n){e(n,t)})}function qn(n){return function(){return(n.unmemoized||n).apply(null,arguments)}}function Bn(n,t,r){return en(function(){return!n.apply(this,arguments)},t,r)}function Fn(n,t){function r(n){return o(function(e,u){if(e)t.apply(null,[e].concat(u));else{var i=n.next();i?u.push(r(i)):u.push(t),sn(n).apply(null,u)}})}return t=f(t||l),lt(n)?n.length?void r(vn(n))():t():t(new Error("First argument to waterfall must be an array of functions"))}var Pn,Un="[object Function]",Cn="[object GeneratorFunction]",Dn=Object.prototype,Hn=Dn.toString,Nn=NaN,Qn=/^\s+|\s+$/g,Rn=/^[-+]0x[0-9a-f]+$/i,Wn=/^0b[01]+$/i,Gn=/^0o[0-7]+$/i,Jn=parseInt,Kn=1/0,Vn=1.7976931348623157e308,Xn="Expected a function",Yn=Math.max,Zn="Expected a function",_n=s("length"),nt=9007199254740991,tt=Object.prototype,rt=tt.hasOwnProperty,et=Object.getPrototypeOf,ut=Object.keys,it="[object Arguments]",ot=Object.prototype,ct=ot.hasOwnProperty,at=ot.toString,ft=ot.propertyIsEnumerable,lt=Array.isArray,st="[object String]",pt=Object.prototype,ht=pt.toString,yt=9007199254740991,mt=/^(?:0|[1-9]\d*)$/,vt=Object.prototype,dt=c(x),gt="function"==typeof setImmediate&&setImmediate;Pn=gt?function(n){gt(n)}:"object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:function(n){setTimeout(n,0)};var kt=Pn,bt=c(A),wt=o(function(n,t){return o(function(r){return n.apply(null,t.concat(r))})}),Et=M(),St=Math.max,jt=Array.prototype.reverse,Lt=K(J),Ot=V(J),xt=o(function(n){var t=[null].concat(n);return function(n){return n.apply(this,t)}}),At=X(x,q,Y),It=X(_,q,Y),Tt=X(A,q,Y),zt=nn("dir"),Mt=X(x,pn,pn),$t=X(_,pn,pn),qt=K(hn),Bt=yn(hn),Ft=V(hn),Pt=nn("log"),Ut=K(dn),Ct=yn(dn),Dt=V(dn),Ht="object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:kt,Nt=Array.prototype.slice,Qt=K(Ln),Rt=yn(Ln),Wt=V(Ln),Gt=X(x,Boolean,q),Jt=X(_,Boolean,q),Kt=Math.ceil,Vt=Math.max,Xt={applyEach:dt,applyEachSeries:bt,apply:wt,asyncify:I,auto:D,cargo:Q,compose:G,concat:Lt,concatSeries:Ot,constant:xt,detect:At,detectLimit:It,detectSeries:Tt,dir:zt,doDuring:rn,doUntil:on,doWhilst:un,during:tn,each:an,eachLimit:fn,eachOf:x,eachOfLimit:_,eachOfSeries:A,eachSeries:ln,ensureAsync:sn,every:Mt,everyLimit:$t,filter:qt,filterLimit:Bt,filterSeries:Ft,forever:mn,iterator:vn,log:Pt,map:Ut,mapLimit:Ct,mapSeries:Dt,memoize:gn,nextTick:Ht,parallel:bn,parallelLimit:wn,priorityQueue:Sn,queue:En,reduce:R,reduceRight:jn,reject:Qt,rejectLimit:Rt,rejectSeries:Wt,retry:xn,seq:W,series:On,setImmediate:kt,some:Gt,someLimit:Jt,sortBy:An,times:Tn,timesLimit:zn,timesSeries:Mn,transform:$n,unmemoize:qn,until:Bn,waterfall:Fn,whilst:en,all:Mt,any:Gt,forEach:an,forEachSeries:ln,forEachLimit:fn,forEachOf:x,forEachOfSeries:A,forEachOfLimit:_,inject:R,foldl:R,foldr:jn,select:qt,selectLimit:Bt,selectSeries:Ft,wrapSync:I};n["default"]=Xt,n.applyEach=dt,n.applyEachSeries=bt,n.apply=wt,n.asyncify=I,n.auto=D,n.cargo=Q,n.compose=G,n.concat=Lt,n.concatSeries=Ot,n.constant=xt,n.detect=At,n.detectLimit=It,n.detectSeries=Tt,n.dir=zt,n.doDuring=rn,n.doUntil=on,n.doWhilst=un,n.during=tn,n.each=an,n.eachLimit=fn,n.eachOf=x,n.eachOfLimit=_,n.eachOfSeries=A,n.eachSeries=ln,n.ensureAsync=sn,n.every=Mt,n.everyLimit=$t,n.filter=qt,n.filterLimit=Bt,n.filterSeries=Ft,n.forever=mn,n.iterator=vn,n.log=Pt,n.map=Ut,n.mapLimit=Ct,n.mapSeries=Dt,n.memoize=gn,n.nextTick=Ht,n.parallel=bn,n.parallelLimit=wn,n.priorityQueue=Sn,n.queue=En,n.reduce=R,n.reduceRight=jn,n.reject=Qt,n.rejectLimit=Rt,n.rejectSeries=Wt,n.retry=xn,n.seq=W,n.series=On,n.setImmediate=kt,n.some=Gt,n.someLimit=Jt,n.sortBy=An,n.times=Tn,n.timesLimit=zn,n.timesSeries=Mn,n.transform=$n,n.unmemoize=qn,n.until=Bn,n.waterfall=Fn,n.whilst=en,n.all=Mt,n.any=Gt,n.forEach=an,n.forEachSeries=ln,n.forEachLimit=fn,n.forEachOf=x,n.forEachOfSeries=A,n.forEachOfLimit=_,n.inject=R,n.foldl=R,n.foldr=jn,n.select=qt,n.selectLimit=Bt,n.selectSeries=Ft,n.wrapSync=I}); //# sourceMappingURL=dist/async.min.map \ No newline at end of file diff --git a/build/bower.json b/build/bower.json new file mode 100644 index 000000000..b2a4f3c71 --- /dev/null +++ b/build/bower.json @@ -0,0 +1,68 @@ +{ + "name": "async", + "description": "Higher-order functions and common patterns for asynchronous code", + "main": "index.js", + "keywords": [ + "async", + "callback", + "module", + "utility" + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/caolan/async.git" + }, + "devDependencies": { + "babel-cli": "^6.3.17", + "babel-core": "^6.3.26", + "babel-plugin-add-module-exports": "~0.1.2", + "babel-plugin-transform-es2015-modules-commonjs": "^6.3.16", + "babel-preset-es2015": "^6.3.13", + "babelify": "^7.2.0", + "benchmark": "bestiejs/benchmark.js", + "bluebird": "^2.9.32", + "chai": "^3.1.0", + "coveralls": "^2.11.2", + "es6-promise": "^2.3.0", + "fs-extra": "^0.26.3", + "gulp": "~3.9.0", + "jscs": "^1.13.1", + "jshint": "~2.8.0", + "karma": "^0.13.2", + "karma-browserify": "^4.2.1", + "karma-firefox-launcher": "^0.1.6", + "karma-mocha": "^0.2.0", + "karma-mocha-reporter": "^1.0.2", + "mocha": "^2.2.5", + "native-promise-only": "^0.8.0-a", + "nodeunit": ">0.0.0", + "nyc": "^2.1.0", + "recursive-readdir": "^1.3.0", + "rimraf": "^2.5.0", + "rollup": "^0.25.0", + "rollup-plugin-npm": "~1.3.0", + "rsvp": "^3.0.18", + "semver": "^4.3.6", + "uglify-js": "~2.4.0", + "vinyl-buffer": "~1.0.0", + "vinyl-source-stream": "~1.1.0", + "xyz": "^0.5.0", + "yargs": "~3.9.1" + }, + "moduleType": [ + "amd", + "globals", + "node" + ], + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "authors": [ + "Caolan McMahon" + ] +} \ No newline at end of file diff --git a/build/component.json b/build/component.json new file mode 100644 index 000000000..b699237fc --- /dev/null +++ b/build/component.json @@ -0,0 +1,17 @@ +{ + "name": "async", + "description": "Higher-order functions and common patterns for asynchronous code", + "version": "2.0.0-alpha", + "keywords": [ + "async", + "callback", + "module", + "utility" + ], + "license": "MIT", + "main": "index.js", + "repository": "caolan/async", + "scripts": [ + "index.js" + ] +} \ No newline at end of file diff --git a/build/es/apply.js b/build/es/apply.js new file mode 100644 index 000000000..eeceb43a7 --- /dev/null +++ b/build/es/apply.js @@ -0,0 +1,9 @@ +'use strict'; + +import rest from 'lodash-es/rest'; + +export default rest(function(fn, args) { + return rest(function(callArgs) { + return fn.apply(null, args.concat(callArgs)); + }); +}); diff --git a/build/es/applyEach.js b/build/es/applyEach.js new file mode 100644 index 000000000..2c5f001da --- /dev/null +++ b/build/es/applyEach.js @@ -0,0 +1,6 @@ +'use strict'; + +import applyEach from './internal/applyEach'; +import eachOf from './eachOf'; + +export default applyEach(eachOf); diff --git a/build/es/applyEachSeries.js b/build/es/applyEachSeries.js new file mode 100644 index 000000000..e917618d6 --- /dev/null +++ b/build/es/applyEachSeries.js @@ -0,0 +1,6 @@ +'use strict'; + +import applyEach from './internal/applyEach'; +import eachOfSeries from './eachOfSeries'; + +export default applyEach(eachOfSeries); diff --git a/build/es/asyncify.js b/build/es/asyncify.js new file mode 100644 index 000000000..9239e9904 --- /dev/null +++ b/build/es/asyncify.js @@ -0,0 +1,26 @@ +'use strict'; + +import isObject from 'lodash-es/isObject'; +import rest from 'lodash-es/rest'; + +export default function asyncify(func) { + return rest(function (args) { + var callback = args.pop(); + var result; + try { + result = func.apply(this, args); + } catch (e) { + return callback(e); + } + // if result is Promise object + if (isObject(result) && typeof result.then === 'function') { + result.then(function(value) { + callback(null, value); + })['catch'](function(err) { + callback(err.message ? err : new Error(err)); + }); + } else { + callback(null, result); + } + }); +} diff --git a/build/es/auto.js b/build/es/auto.js new file mode 100644 index 000000000..19f4215f2 --- /dev/null +++ b/build/es/auto.js @@ -0,0 +1,109 @@ +'use strict'; + +import arrayEach from 'lodash-es/internal/arrayEach'; +import arrayEvery from 'lodash-es/internal/arrayEvery'; +import baseHas from 'lodash-es/internal/baseHas'; +import forOwn from 'lodash-es/forOwn'; +import indexOf from 'lodash-es/indexOf'; +import isArray from 'lodash-es/isArray'; +import okeys from 'lodash-es/keys'; +import noop from 'lodash-es/noop'; +import once from 'lodash-es/once'; +import rest from 'lodash-es/rest'; + +import setImmediate from './internal/setImmediate'; + +export default function (tasks, concurrency, callback) { + if (typeof arguments[1] === 'function') { + // concurrency is optional, shift the args. + callback = concurrency; + concurrency = null; + } + callback = once(callback || noop); + var keys = okeys(tasks); + var remainingTasks = keys.length; + if (!remainingTasks) { + return callback(null); + } + if (!concurrency) { + concurrency = remainingTasks; + } + + var results = {}; + var runningTasks = 0; + + var listeners = []; + function addListener(fn) { + listeners.unshift(fn); + } + function removeListener(fn) { + var idx = indexOf(listeners, fn); + if (idx >= 0) listeners.splice(idx, 1); + } + function taskComplete() { + remainingTasks--; + arrayEach(listeners.slice(), function (fn) { + fn(); + }); + } + + addListener(function () { + if (!remainingTasks) { + callback(null, results); + } + }); + + arrayEach(keys, function (k) { + var task = isArray(tasks[k]) ? tasks[k]: [tasks[k]]; + var taskCallback = rest(function(err, args) { + runningTasks--; + if (args.length <= 1) { + args = args[0]; + } + if (err) { + var safeResults = {}; + forOwn(results, function(val, rkey) { + safeResults[rkey] = val; + }); + safeResults[k] = args; + callback(err, safeResults); + } + else { + results[k] = args; + setImmediate(taskComplete); + } + }); + var requires = task.slice(0, task.length - 1); + // prevent dead-locks + var len = requires.length; + var dep; + while (len--) { + if (!(dep = tasks[requires[len]])) { + throw new Error('Has inexistant dependency'); + } + if (isArray(dep) && indexOf(dep, k) >= 0) { + throw new Error('Has cyclic dependencies'); + } + } + function ready() { + return runningTasks < concurrency && !baseHas(results, k) && + arrayEvery(requires, function (x) { + return baseHas(results, x); + }); + } + if (ready()) { + runningTasks++; + task[task.length - 1](taskCallback, results); + } + else { + addListener(listener); + } + function listener() { + if (ready()) { + runningTasks++; + removeListener(listener); + task[task.length - 1](taskCallback, results); + } + } + }); +} diff --git a/build/es/cargo.js b/build/es/cargo.js new file mode 100644 index 000000000..b90ab0f8a --- /dev/null +++ b/build/es/cargo.js @@ -0,0 +1,7 @@ +'use strict'; + +import queue from './internal/queue'; + +export default function cargo(worker, payload) { + return queue(worker, 1, payload); +} diff --git a/build/es/compose.js b/build/es/compose.js new file mode 100644 index 000000000..9e925211f --- /dev/null +++ b/build/es/compose.js @@ -0,0 +1,9 @@ +'use strict'; + +import seq from './seq'; + +var reverse = Array.prototype.reverse; + +export default function compose(/* functions... */) { + return seq.apply(null, reverse.call(arguments)); +} diff --git a/build/es/concat.js b/build/es/concat.js new file mode 100644 index 000000000..af019a370 --- /dev/null +++ b/build/es/concat.js @@ -0,0 +1,6 @@ +'use strict'; + +import concat from './internal/concat'; +import doParallel from './internal/doParallel'; + +export default doParallel(concat); diff --git a/build/es/concatSeries.js b/build/es/concatSeries.js new file mode 100644 index 000000000..76f404327 --- /dev/null +++ b/build/es/concatSeries.js @@ -0,0 +1,6 @@ +'use strict'; + +import concat from './internal/concat'; +import doSeries from './internal/doSeries'; + +export default doSeries(concat); diff --git a/build/es/constant.js b/build/es/constant.js new file mode 100644 index 000000000..492d11bbd --- /dev/null +++ b/build/es/constant.js @@ -0,0 +1,10 @@ +'use strict'; + +import rest from 'lodash-es/rest'; + +export default rest(function(values) { + var args = [null].concat(values); + return function (cb) { + return cb.apply(this, args); + }; +}); diff --git a/build/es/detect.js b/build/es/detect.js new file mode 100644 index 000000000..19fffef6a --- /dev/null +++ b/build/es/detect.js @@ -0,0 +1,9 @@ +'use strict'; + +import identity from 'lodash-es/identity'; + +import createTester from './internal/createTester'; +import eachOf from './eachOf'; +import findGetResult from './internal/findGetResult'; + +export default createTester(eachOf, identity, findGetResult); diff --git a/build/es/detectLimit.js b/build/es/detectLimit.js new file mode 100644 index 000000000..0fc46db12 --- /dev/null +++ b/build/es/detectLimit.js @@ -0,0 +1,9 @@ +'use strict'; + +import identity from 'lodash-es/identity'; + +import createTester from './internal/createTester'; +import eachOfLimit from './eachOfLimit'; +import findGetResult from './internal/findGetResult'; + +export default createTester(eachOfLimit, identity, findGetResult); diff --git a/build/es/detectSeries.js b/build/es/detectSeries.js new file mode 100644 index 000000000..26f48bac0 --- /dev/null +++ b/build/es/detectSeries.js @@ -0,0 +1,9 @@ +'use strict'; + +import identity from 'lodash-es/identity'; + +import createTester from './internal/createTester'; +import eachOfSeries from './eachOfSeries'; +import findGetResult from './internal/findGetResult'; + +export default createTester(eachOfSeries, identity, findGetResult); diff --git a/build/es/dir.js b/build/es/dir.js new file mode 100644 index 000000000..049b41667 --- /dev/null +++ b/build/es/dir.js @@ -0,0 +1,5 @@ +'use strict'; + +import consoleFunc from './internal/consoleFunc'; + +export default consoleFunc('dir'); diff --git a/build/es/doDuring.js b/build/es/doDuring.js new file mode 100644 index 000000000..c13e62b8b --- /dev/null +++ b/build/es/doDuring.js @@ -0,0 +1,12 @@ +'use strict'; + +import during from './during'; + +export default function doDuring(iterator, test, cb) { + var calls = 0; + + during(function(next) { + if (calls++ < 1) return next(null, true); + test.apply(this, arguments); + }, iterator, cb); +} diff --git a/build/es/doUntil.js b/build/es/doUntil.js new file mode 100644 index 000000000..3bc783fb7 --- /dev/null +++ b/build/es/doUntil.js @@ -0,0 +1,9 @@ +'use strict'; + +import doWhilst from './doWhilst'; + +export default function doUntil(iterator, test, cb) { + return doWhilst(iterator, function() { + return !test.apply(this, arguments); + }, cb); +} diff --git a/build/es/doWhilst.js b/build/es/doWhilst.js new file mode 100644 index 000000000..b05d1d829 --- /dev/null +++ b/build/es/doWhilst.js @@ -0,0 +1,10 @@ +'use strict'; + +import whilst from './whilst'; + +export default function doWhilst(iterator, test, cb) { + var calls = 0; + return whilst(function() { + return ++calls <= 1 || test.apply(this, arguments); + }, iterator, cb); +} diff --git a/build/es/during.js b/build/es/during.js new file mode 100644 index 000000000..e9809cdc1 --- /dev/null +++ b/build/es/during.js @@ -0,0 +1,25 @@ +'use strict'; + +import noop from 'lodash-es/noop'; +import rest from 'lodash-es/rest'; + +export default function during(test, iterator, cb) { + cb = cb || noop; + + var next = rest(function(err, args) { + if (err) { + cb(err); + } else { + args.push(check); + test.apply(this, args); + } + }); + + var check = function(err, truth) { + if (err) return cb(err); + if (!truth) return cb(null); + iterator(next); + }; + + test(check); +} diff --git a/build/es/each.js b/build/es/each.js new file mode 100644 index 000000000..384bb0a89 --- /dev/null +++ b/build/es/each.js @@ -0,0 +1,8 @@ +'use strict'; + +import eachOf from './eachOf'; +import withoutIndex from './internal/withoutIndex'; + +export default function each(arr, iterator, cb) { + return eachOf(arr, withoutIndex(iterator), cb); +} diff --git a/build/es/eachLimit.js b/build/es/eachLimit.js new file mode 100644 index 000000000..5009cc355 --- /dev/null +++ b/build/es/eachLimit.js @@ -0,0 +1,9 @@ +'use strict'; + +import eachOfLimit from './internal/eachOfLimit'; +import withoutIndex from './internal/withoutIndex'; + + +export default function eachLimit(arr, limit, iterator, cb) { + return eachOfLimit(limit)(arr, withoutIndex(iterator), cb); +} diff --git a/build/es/eachOf.js b/build/es/eachOf.js new file mode 100644 index 000000000..e06f2bbd0 --- /dev/null +++ b/build/es/eachOf.js @@ -0,0 +1,34 @@ +'use strict'; + +import once from 'lodash-es/once'; +import noop from 'lodash-es/noop'; + +import keyIterator from './internal/keyIterator'; +import onlyOnce from './internal/onlyOnce'; + +export default function eachOf(object, iterator, callback) { + callback = once(callback || noop); + object = object || []; + + var iter = keyIterator(object); + var key, completed = 0; + + while ((key = iter()) != null) { + completed += 1; + iterator(object[key], key, onlyOnce(done)); + } + + if (completed === 0) callback(null); + + function done(err) { + completed--; + if (err) { + callback(err); + } + // Check key is null in case iterator isn't exhausted + // and done resolved synchronously. + else if (key === null && completed <= 0) { + callback(null); + } + } +} diff --git a/build/es/eachOfLimit.js b/build/es/eachOfLimit.js new file mode 100644 index 000000000..e38147412 --- /dev/null +++ b/build/es/eachOfLimit.js @@ -0,0 +1,7 @@ +'use strict'; + +import _eachOfLimit from './internal/eachOfLimit'; + +export default function eachOfLimit(obj, limit, iterator, cb) { + _eachOfLimit(limit)(obj, iterator, cb); +} diff --git a/build/es/eachOfSeries.js b/build/es/eachOfSeries.js new file mode 100644 index 000000000..2456bbb9f --- /dev/null +++ b/build/es/eachOfSeries.js @@ -0,0 +1,40 @@ +'use strict'; + +import once from 'lodash-es/once'; +import noop from 'lodash-es/noop'; + +import keyIterator from './internal/keyIterator'; +import onlyOnce from './internal/onlyOnce'; +import setImmediate from './setImmediate'; + +export default function eachOfSeries(obj, iterator, callback) { + callback = once(callback || noop); + obj = obj || []; + var nextKey = keyIterator(obj); + var key = nextKey(); + + function iterate() { + var sync = true; + if (key === null) { + return callback(null); + } + iterator(obj[key], key, onlyOnce(function(err) { + if (err) { + callback(err); + } else { + key = nextKey(); + if (key === null) { + return callback(null); + } else { + if (sync) { + setImmediate(iterate); + } else { + iterate(); + } + } + } + })); + sync = false; + } + iterate(); +} diff --git a/build/es/eachSeries.js b/build/es/eachSeries.js new file mode 100644 index 000000000..fd08c0407 --- /dev/null +++ b/build/es/eachSeries.js @@ -0,0 +1,8 @@ +'use strict'; + +import eachOfSeries from './eachOfSeries'; +import withoutIndex from './internal/withoutIndex'; + +export default function eachSeries(arr, iterator, cb) { + return eachOfSeries(arr, withoutIndex(iterator), cb); +} diff --git a/build/es/ensureAsync.js b/build/es/ensureAsync.js new file mode 100644 index 000000000..ba9affd57 --- /dev/null +++ b/build/es/ensureAsync.js @@ -0,0 +1,24 @@ +'use strict'; + +import rest from 'lodash-es/rest'; + +import setImmediate from './internal/setImmediate'; + +export default function ensureAsync(fn) { + return rest(function (args) { + var callback = args.pop(); + var sync = true; + args.push(function () { + var innerArgs = arguments; + if (sync) { + setImmediate(function () { + callback.apply(null, innerArgs); + }); + } else { + callback.apply(null, innerArgs); + } + }); + fn.apply(this, args); + sync = false; + }); +} diff --git a/build/es/every.js b/build/es/every.js new file mode 100644 index 000000000..7ee371376 --- /dev/null +++ b/build/es/every.js @@ -0,0 +1,7 @@ +'use strict'; + +import createTester from './internal/createTester'; +import eachOf from './eachOf'; +import notId from './internal/notId'; + +export default createTester(eachOf, notId, notId); diff --git a/build/es/everyLimit.js b/build/es/everyLimit.js new file mode 100644 index 000000000..4b3fc5fb4 --- /dev/null +++ b/build/es/everyLimit.js @@ -0,0 +1,7 @@ +'use strict'; + +import createTester from './internal/createTester'; +import eachOfLimit from './eachOfLimit'; +import notId from './internal/notId'; + +export default createTester(eachOfLimit, notId, notId); diff --git a/build/es/filter.js b/build/es/filter.js new file mode 100644 index 000000000..36af2b1c8 --- /dev/null +++ b/build/es/filter.js @@ -0,0 +1,6 @@ +'use strict'; + +import filter from './internal/filter'; +import doParallel from './internal/doParallel'; + +export default doParallel(filter); diff --git a/build/es/filterLimit.js b/build/es/filterLimit.js new file mode 100644 index 000000000..8fe237ffc --- /dev/null +++ b/build/es/filterLimit.js @@ -0,0 +1,6 @@ +'use strict'; + +import filter from './internal/filter'; +import doParallelLimit from './internal/doParallelLimit'; + +export default doParallelLimit(filter); diff --git a/build/es/filterSeries.js b/build/es/filterSeries.js new file mode 100644 index 000000000..861ca8b20 --- /dev/null +++ b/build/es/filterSeries.js @@ -0,0 +1,6 @@ +'use strict'; + +import filter from './internal/filter'; +import doSeries from './internal/doSeries'; + +export default doSeries(filter); diff --git a/build/es/forever.js b/build/es/forever.js new file mode 100644 index 000000000..fca06846e --- /dev/null +++ b/build/es/forever.js @@ -0,0 +1,17 @@ +'use strict'; + +import noop from 'lodash-es/noop'; + +import onlyOnce from './internal/onlyOnce'; +import ensureAsync from './ensureAsync'; + +export default function forever(fn, cb) { + var done = onlyOnce(cb || noop); + var task = ensureAsync(fn); + + function next(err) { + if (err) return done(err); + task(next); + } + next(); +} diff --git a/build/es/index.js b/build/es/index.js new file mode 100644 index 000000000..a165909d4 --- /dev/null +++ b/build/es/index.js @@ -0,0 +1,228 @@ +'use strict'; + +import applyEach from './applyEach'; +import applyEachSeries from './applyEachSeries'; +import apply from './apply'; +import asyncify from './asyncify'; +import auto from './auto'; +import cargo from './cargo'; +import compose from './compose'; +import concat from './concat'; +import concatSeries from './concatSeries'; +import constant from './constant'; +import detect from './detect'; +import detectLimit from './detectLimit'; +import detectSeries from './detectSeries'; +import dir from './dir'; +import doDuring from './doDuring'; +import doUntil from './doUntil'; +import doWhilst from './doWhilst'; +import during from './during'; +import each from './each'; +import eachLimit from './eachLimit'; +import eachOf from './eachOf'; +import eachOfLimit from './eachOfLimit'; +import eachOfSeries from './eachOfSeries'; +import eachSeries from './eachSeries'; +import ensureAsync from './ensureAsync'; +import every from './every'; +import everyLimit from './everyLimit'; +import filter from './filter'; +import filterLimit from './filterLimit'; +import filterSeries from './filterSeries'; +import forever from './forever'; +import iterator from './iterator'; +import log from './log'; +import map from './map'; +import mapLimit from './mapLimit'; +import mapSeries from './mapSeries'; +import memoize from './memoize'; +import nextTick from './nextTick'; +import parallel from './parallel'; +import parallelLimit from './parallelLimit'; +import priorityQueue from './priorityQueue'; +import queue from './queue'; +import reduce from './reduce'; +import reduceRight from './reduceRight'; +import reject from './reject'; +import rejectLimit from './rejectLimit'; +import rejectSeries from './rejectSeries'; +import retry from './retry'; +import seq from './seq'; +import series from './series'; +import setImmediate from './setImmediate'; +import some from './some'; +import someLimit from './someLimit'; +import sortBy from './sortBy'; +import times from './times'; +import timesLimit from './timesLimit'; +import timesSeries from './timesSeries'; +import transform from './transform'; +import unmemoize from './unmemoize'; +import until from './until'; +import waterfall from './waterfall'; +import whilst from './whilst'; + +export default { + applyEach: applyEach, + applyEachSeries: applyEachSeries, + apply: apply, + asyncify: asyncify, + auto: auto, + cargo: cargo, + compose: compose, + concat: concat, + concatSeries: concatSeries, + constant: constant, + detect: detect, + detectLimit: detectLimit, + detectSeries: detectSeries, + dir: dir, + doDuring: doDuring, + doUntil: doUntil, + doWhilst: doWhilst, + during: during, + each: each, + eachLimit: eachLimit, + eachOf: eachOf, + eachOfLimit: eachOfLimit, + eachOfSeries: eachOfSeries, + eachSeries: eachSeries, + ensureAsync: ensureAsync, + every: every, + everyLimit: everyLimit, + filter: filter, + filterLimit: filterLimit, + filterSeries: filterSeries, + forever: forever, + iterator: iterator, + log: log, + map: map, + mapLimit: mapLimit, + mapSeries: mapSeries, + memoize: memoize, + nextTick: nextTick, + parallel: parallel, + parallelLimit: parallelLimit, + priorityQueue: priorityQueue, + queue: queue, + reduce: reduce, + reduceRight: reduceRight, + reject: reject, + rejectLimit: rejectLimit, + rejectSeries: rejectSeries, + retry: retry, + seq: seq, + series: series, + setImmediate: setImmediate, + some: some, + someLimit: someLimit, + sortBy: sortBy, + times: times, + timesLimit: timesLimit, + timesSeries: timesSeries, + transform: transform, + unmemoize: unmemoize, + until: until, + waterfall: waterfall, + whilst: whilst, + + // aliases + all: every, + any: some, + forEach: each, + forEachSeries: eachSeries, + forEachLimit: eachLimit, + forEachOf: eachOf, + forEachOfSeries: eachOfSeries, + forEachOfLimit: eachOfLimit, + inject: reduce, + foldl: reduce, + foldr: reduceRight, + select: filter, + selectLimit: filterLimit, + selectSeries: filterSeries, + wrapSync: asyncify +}; + +export { + applyEach as applyEach, + applyEachSeries as applyEachSeries, + apply as apply, + asyncify as asyncify, + auto as auto, + cargo as cargo, + compose as compose, + concat as concat, + concatSeries as concatSeries, + constant as constant, + detect as detect, + detectLimit as detectLimit, + detectSeries as detectSeries, + dir as dir, + doDuring as doDuring, + doUntil as doUntil, + doWhilst as doWhilst, + during as during, + each as each, + eachLimit as eachLimit, + eachOf as eachOf, + eachOfLimit as eachOfLimit, + eachOfSeries as eachOfSeries, + eachSeries as eachSeries, + ensureAsync as ensureAsync, + every as every, + everyLimit as everyLimit, + filter as filter, + filterLimit as filterLimit, + filterSeries as filterSeries, + forever as forever, + iterator as iterator, + log as log, + map as map, + mapLimit as mapLimit, + mapSeries as mapSeries, + memoize as memoize, + nextTick as nextTick, + parallel as parallel, + parallelLimit as parallelLimit, + priorityQueue as priorityQueue, + queue as queue, + reduce as reduce, + reduceRight as reduceRight, + reject as reject, + rejectLimit as rejectLimit, + rejectSeries as rejectSeries, + retry as retry, + seq as seq, + series as series, + setImmediate as setImmediate, + some as some, + someLimit as someLimit, + sortBy as sortBy, + times as times, + timesLimit as timesLimit, + timesSeries as timesSeries, + transform as transform, + unmemoize as unmemoize, + until as until, + waterfall as waterfall, + whilst as whilst, + + // Aliases + every as all, + some as any, + each as forEach, + eachSeries as forEachSeries, + eachLimit as forEachLimit, + eachOf as forEachOf, + eachOfSeries as forEachOfSeries, + eachOfLimit as forEachOfLimit, + reduce as inject, + reduce as foldl, + reduceRight as foldr, + filter as select, + filterLimit as selectLimit, + filterSeries as selectSeries, + asyncify as wrapSync +}; diff --git a/build/es/internal/applyEach.js b/build/es/internal/applyEach.js new file mode 100644 index 000000000..1467363b7 --- /dev/null +++ b/build/es/internal/applyEach.js @@ -0,0 +1,22 @@ +'use strict'; + +import rest from 'lodash-es/rest'; + +export default function applyEach(eachfn) { + return rest(function(fns, args) { + var go = rest(function(args) { + var that = this; + var callback = args.pop(); + return eachfn(fns, function (fn, _, cb) { + fn.apply(that, args.concat([cb])); + }, + callback); + }); + if (args.length) { + return go.apply(this, args); + } + else { + return go; + } + }); +} diff --git a/build/es/internal/concat.js b/build/es/internal/concat.js new file mode 100644 index 000000000..482ad3a1c --- /dev/null +++ b/build/es/internal/concat.js @@ -0,0 +1,13 @@ +'use strict'; + +export default function concat(eachfn, arr, fn, callback) { + var result = []; + eachfn(arr, function (x, index, cb) { + fn(x, function (err, y) { + result = result.concat(y || []); + cb(err); + }); + }, function (err) { + callback(err, result); + }); +} diff --git a/build/es/internal/consoleFunc.js b/build/es/internal/consoleFunc.js new file mode 100644 index 000000000..7796d876e --- /dev/null +++ b/build/es/internal/consoleFunc.js @@ -0,0 +1,23 @@ +'use strict'; + +import arrayEach from 'lodash-es/internal/arrayEach'; +import rest from 'lodash-es/rest'; + +export default function consoleFunc(name) { + return rest(function (fn, args) { + fn.apply(null, args.concat([rest(function (err, args) { + if (typeof console === 'object') { + if (err) { + if (console.error) { + console.error(err); + } + } + else if (console[name]) { + arrayEach(args, function (x) { + console[name](x); + }); + } + } + })])); + }); +} diff --git a/build/es/internal/createTester.js b/build/es/internal/createTester.js new file mode 100644 index 000000000..1bf2e8904 --- /dev/null +++ b/build/es/internal/createTester.js @@ -0,0 +1,26 @@ +'use strict'; + +export default function _createTester(eachfn, check, getResult) { + return function(arr, limit, iterator, cb) { + function done() { + if (cb) cb(getResult(false, void 0)); + } + function iteratee(x, _, callback) { + if (!cb) return callback(); + iterator(x, function (v) { + if (cb && check(v)) { + cb(getResult(true, x)); + cb = iterator = false; + } + callback(); + }); + } + if (arguments.length > 3) { + eachfn(arr, limit, iteratee, done); + } else { + cb = iterator; + iterator = limit; + eachfn(arr, iteratee, done); + } + }; +} diff --git a/build/es/internal/doParallel.js b/build/es/internal/doParallel.js new file mode 100644 index 000000000..19c90fc06 --- /dev/null +++ b/build/es/internal/doParallel.js @@ -0,0 +1,9 @@ +'use strict'; + +import eachOf from '../eachOf'; + +export default function doParallel(fn) { + return function (obj, iterator, callback) { + return fn(eachOf, obj, iterator, callback); + }; +} diff --git a/build/es/internal/doParallelLimit.js b/build/es/internal/doParallelLimit.js new file mode 100644 index 000000000..0c3bcf7b7 --- /dev/null +++ b/build/es/internal/doParallelLimit.js @@ -0,0 +1,9 @@ +'use strict'; + +import eachOfLimit from './eachOfLimit'; + +export default function doParallelLimit(fn) { + return function (obj, limit, iterator, callback) { + return fn(eachOfLimit(limit), obj, iterator, callback); + }; +} diff --git a/build/es/internal/doSeries.js b/build/es/internal/doSeries.js new file mode 100644 index 000000000..c7f1d99b0 --- /dev/null +++ b/build/es/internal/doSeries.js @@ -0,0 +1,9 @@ +'use strict'; + +import eachOfSeries from '../eachOfSeries'; + +export default function doSeries(fn) { + return function (obj, iterator, callback) { + return fn(eachOfSeries, obj, iterator, callback); + }; +} diff --git a/build/es/internal/eachOfLimit.js b/build/es/internal/eachOfLimit.js new file mode 100644 index 000000000..5235278cf --- /dev/null +++ b/build/es/internal/eachOfLimit.js @@ -0,0 +1,49 @@ +'use strict'; + +import noop from 'lodash-es/noop'; +import once from 'lodash-es/once'; + +import keyIterator from './keyIterator'; +import onlyOnce from './onlyOnce'; + +export default function _eachOfLimit(limit) { + return function (obj, iterator, callback) { + callback = once(callback || noop); + obj = obj || []; + var nextKey = keyIterator(obj); + if (limit <= 0) { + return callback(null); + } + var done = false; + var running = 0; + var errored = false; + + (function replenish () { + if (done && running <= 0) { + return callback(null); + } + + while (running < limit && !errored) { + var key = nextKey(); + if (key === null) { + done = true; + if (running <= 0) { + callback(null); + } + return; + } + running += 1; + iterator(obj[key], key, onlyOnce(function (err) { + running -= 1; + if (err) { + callback(err); + errored = true; + } + else { + replenish(); + } + })); + } + })(); + }; +} diff --git a/build/es/internal/filter.js b/build/es/internal/filter.js new file mode 100644 index 000000000..f58eb5226 --- /dev/null +++ b/build/es/internal/filter.js @@ -0,0 +1,20 @@ +'use strict'; + +import arrayMap from 'lodash-es/internal/arrayMap'; +import property from 'lodash-es/internal/baseProperty'; + +export default function _filter(eachfn, arr, iterator, callback) { + var results = []; + eachfn(arr, function (x, index, callback) { + iterator(x, function (v) { + if (v) { + results.push({index: index, value: x}); + } + callback(); + }); + }, function () { + callback(arrayMap(results.sort(function (a, b) { + return a.index - b.index; + }), property('value'))); + }); +} diff --git a/build/es/internal/findGetResult.js b/build/es/internal/findGetResult.js new file mode 100644 index 000000000..3aeb07dfd --- /dev/null +++ b/build/es/internal/findGetResult.js @@ -0,0 +1,5 @@ +'use strict'; + +export default function _findGetResult(v, x) { + return x; +} diff --git a/build/es/internal/keyIterator.js b/build/es/internal/keyIterator.js new file mode 100644 index 000000000..9f12beb33 --- /dev/null +++ b/build/es/internal/keyIterator.js @@ -0,0 +1,23 @@ +'use strict'; + +import isArrayLike from 'lodash-es/isArrayLike'; +import keys from 'lodash-es/keys'; + +export default function keyIterator(coll) { + var i = -1; + var len; + if (isArrayLike(coll)) { + len = coll.length; + return function next() { + i++; + return i < len ? i : null; + }; + } else { + var okeys = keys(coll); + len = okeys.length; + return function next() { + i++; + return i < len ? okeys[i] : null; + }; + } +} diff --git a/build/es/internal/map.js b/build/es/internal/map.js new file mode 100644 index 000000000..5057f4907 --- /dev/null +++ b/build/es/internal/map.js @@ -0,0 +1,19 @@ +'use strict'; + +import isArrayLike from 'lodash-es/isArrayLike'; +import noop from 'lodash-es/noop'; +import once from 'lodash-es/once'; + +export default function _asyncMap(eachfn, arr, iterator, callback) { + callback = once(callback || noop); + arr = arr || []; + var results = isArrayLike(arr) ? [] : {}; + eachfn(arr, function (value, index, callback) { + iterator(value, function (err, v) { + results[index] = v; + callback(err); + }); + }, function (err) { + callback(err, results); + }); +} diff --git a/build/es/internal/notId.js b/build/es/internal/notId.js new file mode 100644 index 000000000..d936aabba --- /dev/null +++ b/build/es/internal/notId.js @@ -0,0 +1,5 @@ +'use strict'; + +export default function notId(v) { + return !v; +} diff --git a/build/es/internal/onlyOnce.js b/build/es/internal/onlyOnce.js new file mode 100644 index 000000000..f4241c813 --- /dev/null +++ b/build/es/internal/onlyOnce.js @@ -0,0 +1,9 @@ +'use strict'; + +export default function onlyOnce(fn) { + return function() { + if (fn === null) throw new Error("Callback was already called."); + fn.apply(this, arguments); + fn = null; + }; +} diff --git a/build/es/internal/parallel.js b/build/es/internal/parallel.js new file mode 100644 index 000000000..b53290823 --- /dev/null +++ b/build/es/internal/parallel.js @@ -0,0 +1,22 @@ +'use strict'; + +import noop from 'lodash-es/noop'; +import isArrayLike from 'lodash-es/isArrayLike'; +import rest from 'lodash-es/rest'; + +export default function _parallel(eachfn, tasks, callback) { + callback = callback || noop; + var results = isArrayLike(tasks) ? [] : {}; + + eachfn(tasks, function (task, key, callback) { + task(rest(function (err, args) { + if (args.length <= 1) { + args = args[0]; + } + results[key] = args; + callback(err); + })); + }, function (err) { + callback(err, results); + }); +} diff --git a/build/es/internal/queue.js b/build/es/internal/queue.js new file mode 100644 index 000000000..2e291e30f --- /dev/null +++ b/build/es/internal/queue.js @@ -0,0 +1,140 @@ +'use strict'; + +import arrayEach from 'lodash-es/internal/arrayEach'; +import arrayMap from 'lodash-es/internal/arrayMap'; +import isArray from 'lodash-es/isArray'; +import noop from 'lodash-es/noop'; +import property from 'lodash-es/internal/baseProperty'; + +import onlyOnce from './onlyOnce'; +import setImmediate from './setImmediate'; + +export default function queue(worker, concurrency, payload) { + if (concurrency == null) { + concurrency = 1; + } + else if(concurrency === 0) { + throw new Error('Concurrency must not be zero'); + } + function _insert(q, data, pos, callback) { + if (callback != null && typeof callback !== 'function') { + throw new Error('task callback must be a function'); + } + q.started = true; + if (!isArray(data)) { + data = [data]; + } + if(data.length === 0 && q.idle()) { + // call drain immediately if there are no tasks + return setImmediate(function() { + q.drain(); + }); + } + arrayEach(data, function(task) { + var item = { + data: task, + callback: callback || noop + }; + + if (pos) { + q.tasks.unshift(item); + } else { + q.tasks.push(item); + } + + if (q.tasks.length === q.concurrency) { + q.saturated(); + } + }); + setImmediate(q.process); + } + function _next(q, tasks) { + return function(){ + workers -= 1; + + var removed = false; + var args = arguments; + arrayEach(tasks, function (task) { + arrayEach(workersList, function (worker, index) { + if (worker === task && !removed) { + workersList.splice(index, 1); + removed = true; + } + }); + + task.callback.apply(task, args); + }); + if (q.tasks.length + workers === 0) { + q.drain(); + } + q.process(); + }; + } + + var workers = 0; + var workersList = []; + var q = { + tasks: [], + concurrency: concurrency, + payload: payload, + saturated: noop, + empty: noop, + drain: noop, + started: false, + paused: false, + push: function (data, callback) { + _insert(q, data, false, callback); + }, + kill: function () { + q.drain = noop; + q.tasks = []; + }, + unshift: function (data, callback) { + _insert(q, data, true, callback); + }, + process: function () { + while(!q.paused && workers < q.concurrency && q.tasks.length){ + + var tasks = q.payload ? + q.tasks.splice(0, q.payload) : + q.tasks.splice(0, q.tasks.length); + + var data = arrayMap(tasks, property('data')); + + if (q.tasks.length === 0) { + q.empty(); + } + workers += 1; + workersList.push(tasks[0]); + var cb = onlyOnce(_next(q, tasks)); + worker(data, cb); + } + }, + length: function () { + return q.tasks.length; + }, + running: function () { + return workers; + }, + workersList: function () { + return workersList; + }, + idle: function() { + return q.tasks.length + workers === 0; + }, + pause: function () { + q.paused = true; + }, + resume: function () { + if (q.paused === false) { return; } + q.paused = false; + var resumeCount = Math.min(q.concurrency, q.tasks.length); + // Need to call q.process once per concurrent + // worker to preserve full concurrency after pause + for (var w = 1; w <= resumeCount; w++) { + setImmediate(q.process); + } + } + }; + return q; +} diff --git a/build/es/internal/reject.js b/build/es/internal/reject.js new file mode 100644 index 000000000..8b1bf0d5c --- /dev/null +++ b/build/es/internal/reject.js @@ -0,0 +1,11 @@ +'use strict'; + +import filter from './filter'; + +export default function reject(eachfn, arr, iterator, callback) { + filter(eachfn, arr, function(value, cb) { + iterator(value, function(v) { + cb(!v); + }); + }, callback); +} diff --git a/build/es/internal/setImmediate.js b/build/es/internal/setImmediate.js new file mode 100644 index 000000000..c02ad7160 --- /dev/null +++ b/build/es/internal/setImmediate.js @@ -0,0 +1,19 @@ +'use strict'; + +var _setImmediate = typeof setImmediate === 'function' && setImmediate; + +var _delay; +if (_setImmediate) { + _delay = function(fn) { + // not a direct alias for IE10 compatibility + _setImmediate(fn); + }; +} else if (typeof process === 'object' && typeof process.nextTick === 'function') { + _delay = process.nextTick; +} else { + _delay = function(fn) { + setTimeout(fn, 0); + }; +} + +export default _delay; diff --git a/build/es/internal/withoutIndex.js b/build/es/internal/withoutIndex.js new file mode 100644 index 000000000..f163ff36f --- /dev/null +++ b/build/es/internal/withoutIndex.js @@ -0,0 +1,7 @@ +'use strict'; + +export default function _withoutIndex(iterator) { + return function (value, index, callback) { + return iterator(value, callback); + }; +} diff --git a/build/es/iterator.js b/build/es/iterator.js new file mode 100644 index 000000000..568171a1e --- /dev/null +++ b/build/es/iterator.js @@ -0,0 +1,17 @@ +'use strict'; + +export default function(tasks) { + function makeCallback(index) { + function fn() { + if (tasks.length) { + tasks[index].apply(null, arguments); + } + return fn.next(); + } + fn.next = function() { + return (index < tasks.length - 1) ? makeCallback(index + 1) : null; + }; + return fn; + } + return makeCallback(0); +} diff --git a/build/es/log.js b/build/es/log.js new file mode 100644 index 000000000..b58126412 --- /dev/null +++ b/build/es/log.js @@ -0,0 +1,5 @@ +'use strict'; + +import consoleFunc from './internal/consoleFunc'; + +export default consoleFunc('log'); diff --git a/build/es/map.js b/build/es/map.js new file mode 100644 index 000000000..2a8449c25 --- /dev/null +++ b/build/es/map.js @@ -0,0 +1,6 @@ +'use strict'; + +import doParallel from './internal/doParallel'; +import map from './internal/map'; + +export default doParallel(map); diff --git a/build/es/mapLimit.js b/build/es/mapLimit.js new file mode 100644 index 000000000..642b4c656 --- /dev/null +++ b/build/es/mapLimit.js @@ -0,0 +1,6 @@ +'use strict'; + +import doParallelLimit from './internal/doParallelLimit'; +import map from './internal/map'; + +export default doParallelLimit(map); diff --git a/build/es/mapSeries.js b/build/es/mapSeries.js new file mode 100644 index 000000000..bfcdaa23c --- /dev/null +++ b/build/es/mapSeries.js @@ -0,0 +1,6 @@ +'use strict'; + +import map from './internal/map'; +import doSeries from './internal/doSeries'; + +export default doSeries(map); diff --git a/build/es/memoize.js b/build/es/memoize.js new file mode 100644 index 000000000..184f0d6a0 --- /dev/null +++ b/build/es/memoize.js @@ -0,0 +1,36 @@ +'use strict'; + +import identity from 'lodash-es/identity'; +import rest from 'lodash-es/rest'; + +import setImmediate from './internal/setImmediate'; + +export default function memoize(fn, hasher) { + var memo = {}; + var queues = {}; + hasher = hasher || identity; + var memoized = rest(function memoized(args) { + var callback = args.pop(); + var key = hasher.apply(null, args); + if (key in memo) { + setImmediate(function() { + callback.apply(null, memo[key]); + }); + } else if (key in queues) { + queues[key].push(callback); + } else { + queues[key] = [callback]; + fn.apply(null, args.concat([rest(function(args) { + memo[key] = args; + var q = queues[key]; + delete queues[key]; + for (var i = 0, l = q.length; i < l; i++) { + q[i].apply(null, args); + } + })])); + } + }); + memoized.memo = memo; + memoized.unmemoized = fn; + return memoized; +} diff --git a/build/es/nextTick.js b/build/es/nextTick.js new file mode 100644 index 000000000..b61a8b4a9 --- /dev/null +++ b/build/es/nextTick.js @@ -0,0 +1,7 @@ +'use strict'; + +import setImmediate from './internal/setImmediate'; + +var nexTick = typeof process === 'object' && typeof process.nextTick === 'function' ? process.nextTick : setImmediate; + +export default nexTick; diff --git a/build/es/parallel.js b/build/es/parallel.js new file mode 100644 index 000000000..d3eec16a4 --- /dev/null +++ b/build/es/parallel.js @@ -0,0 +1,8 @@ +'use strict'; + +import _parallel from './internal/parallel'; +import eachOf from './eachOf'; + +export default function parallel(tasks, cb) { + return _parallel(eachOf, tasks, cb); +} diff --git a/build/es/parallelLimit.js b/build/es/parallelLimit.js new file mode 100644 index 000000000..7e66beda3 --- /dev/null +++ b/build/es/parallelLimit.js @@ -0,0 +1,8 @@ +'use strict'; + +import eachOfLimit from './internal/eachOfLimit'; +import parallel from './internal/parallel'; + +export default function parallelLimit(tasks, limit, cb) { + return parallel(eachOfLimit(limit), tasks, cb); +} diff --git a/build/es/priorityQueue.js b/build/es/priorityQueue.js new file mode 100644 index 000000000..9f9d3a0d0 --- /dev/null +++ b/build/es/priorityQueue.js @@ -0,0 +1,72 @@ +'use strict'; + +import arrayEach from 'lodash-es/internal/arrayEach'; +import isArray from 'lodash-es/isArray'; +import noop from 'lodash-es/noop'; + +import setImmediate from './setImmediate'; + +import queue from './queue'; + +export default function(worker, concurrency) { + function _compareTasks(a, b) { + return a.priority - b.priority; + } + + function _binarySearch(sequence, item, compare) { + var beg = -1, + end = sequence.length - 1; + while (beg < end) { + var mid = beg + ((end - beg + 1) >>> 1); + if (compare(item, sequence[mid]) >= 0) { + beg = mid; + } else { + end = mid - 1; + } + } + return beg; + } + + function _insert(q, data, priority, callback) { + if (callback != null && typeof callback !== 'function') { + throw new Error('task callback must be a function'); + } + q.started = true; + if (!isArray(data)) { + data = [data]; + } + if (data.length === 0) { + // call drain immediately if there are no tasks + return setImmediate(function() { + q.drain(); + }); + } + arrayEach(data, function(task) { + var item = { + data: task, + priority: priority, + callback: typeof callback === 'function' ? callback : noop + }; + + q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item); + + if (q.tasks.length === q.concurrency) { + q.saturated(); + } + setImmediate(q.process); + }); + } + + // Start with a normal queue + var q = queue(worker, concurrency); + + // Override push to accept second parameter representing priority + q.push = function(data, priority, callback) { + _insert(q, data, priority, callback); + }; + + // Remove unshift function + delete q.unshift; + + return q; +} diff --git a/build/es/queue.js b/build/es/queue.js new file mode 100644 index 000000000..de2ac93bb --- /dev/null +++ b/build/es/queue.js @@ -0,0 +1,9 @@ +'use strict'; + +import queue from './internal/queue'; + +export default function (worker, concurrency) { + return queue(function (items, cb) { + worker(items[0], cb); + }, concurrency, 1); +} diff --git a/build/es/reduce.js b/build/es/reduce.js new file mode 100644 index 000000000..51b736a8b --- /dev/null +++ b/build/es/reduce.js @@ -0,0 +1,14 @@ +'use strict'; + +import eachOfSeries from './eachOfSeries'; + +export default function reduce(arr, memo, iterator, cb) { + eachOfSeries(arr, function(x, i, cb) { + iterator(memo, x, function(err, v) { + memo = v; + cb(err); + }); + }, function(err) { + cb(err, memo); + }); +} diff --git a/build/es/reduceRight.js b/build/es/reduceRight.js new file mode 100644 index 000000000..730e32080 --- /dev/null +++ b/build/es/reduceRight.js @@ -0,0 +1,10 @@ +'use strict'; + +import reduce from './reduce'; + +var slice = Array.prototype.slice; + +export default function reduceRight (arr, memo, iterator, cb) { + var reversed = slice.call(arr).reverse(); + reduce(reversed, memo, iterator, cb); +} diff --git a/build/es/reject.js b/build/es/reject.js new file mode 100644 index 000000000..fb5b87f3f --- /dev/null +++ b/build/es/reject.js @@ -0,0 +1,6 @@ +'use strict'; + +import reject from './internal/reject'; +import doParallel from './internal/doParallel'; + +export default doParallel(reject); diff --git a/build/es/rejectLimit.js b/build/es/rejectLimit.js new file mode 100644 index 000000000..7cefed66a --- /dev/null +++ b/build/es/rejectLimit.js @@ -0,0 +1,6 @@ +'use strict'; + +import reject from './internal/reject'; +import doParallelLimit from './internal/doParallelLimit'; + +export default doParallelLimit(reject); diff --git a/build/es/rejectSeries.js b/build/es/rejectSeries.js new file mode 100644 index 000000000..e02adeadd --- /dev/null +++ b/build/es/rejectSeries.js @@ -0,0 +1,6 @@ +'use strict'; + +import reject from './internal/reject'; +import doSeries from './internal/doSeries'; + +export default doSeries(reject); diff --git a/build/es/retry.js b/build/es/retry.js new file mode 100644 index 000000000..506a42424 --- /dev/null +++ b/build/es/retry.js @@ -0,0 +1,77 @@ +'use strict'; + +import series from './series'; + +export default function retry(times, task, callback) { + var DEFAULT_TIMES = 5; + var DEFAULT_INTERVAL = 0; + + var attempts = []; + + var opts = { + times: DEFAULT_TIMES, + interval: DEFAULT_INTERVAL + }; + + function parseTimes(acc, t) { + if (typeof t === 'number') { + acc.times = parseInt(t, 10) || DEFAULT_TIMES; + } else if (typeof t === 'object') { + acc.times = parseInt(t.times, 10) || DEFAULT_TIMES; + acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL; + } else { + throw new Error('Unsupported argument type for \'times\': ' + typeof t); + } + } + + var length = arguments.length; + if (length < 1 || length > 3) { + throw new Error('Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)'); + } else if (length <= 2 && typeof times === 'function') { + callback = task; + task = times; + } + if (typeof times !== 'function') { + parseTimes(opts, times); + } + opts.callback = callback; + opts.task = task; + + function wrappedTask(wrappedCallback, wrappedResults) { + function retryAttempt(task, finalAttempt) { + return function(seriesCallback) { + task(function(err, result) { + seriesCallback(!err || finalAttempt, { + err: err, + result: result + }); + }, wrappedResults); + }; + } + + function retryInterval(interval) { + return function(seriesCallback) { + setTimeout(function() { + seriesCallback(null); + }, interval); + }; + } + + while (opts.times) { + + var finalAttempt = !(opts.times -= 1); + attempts.push(retryAttempt(opts.task, finalAttempt)); + if (!finalAttempt && opts.interval > 0) { + attempts.push(retryInterval(opts.interval)); + } + } + + series(attempts, function(done, data) { + data = data[data.length - 1]; + (wrappedCallback || opts.callback)(data.err, data.result); + }); + } + + // If a callback is passed, run this as a controll flow + return opts.callback ? wrappedTask() : wrappedTask; +} diff --git a/build/es/seq.js b/build/es/seq.js new file mode 100644 index 000000000..c9e02c18a --- /dev/null +++ b/build/es/seq.js @@ -0,0 +1,28 @@ +'use strict'; + +import noop from 'lodash-es/noop'; +import rest from 'lodash-es/rest'; +import reduce from './reduce'; + +export default function seq( /* functions... */ ) { + var fns = arguments; + return rest(function(args) { + var that = this; + + var cb = args[args.length - 1]; + if (typeof cb == 'function') { + args.pop(); + } else { + cb = noop; + } + + reduce(fns, args, function(newargs, fn, cb) { + fn.apply(that, newargs.concat([rest(function(err, nextargs) { + cb(err, nextargs); + })])); + }, + function(err, results) { + cb.apply(that, [err].concat(results)); + }); + }); +} diff --git a/build/es/series.js b/build/es/series.js new file mode 100644 index 000000000..bd8e15d7d --- /dev/null +++ b/build/es/series.js @@ -0,0 +1,8 @@ +'use strict'; + +import parallel from './internal/parallel'; +import eachOfSeries from './eachOfSeries'; + +export default function series(tasks, cb) { + return parallel(eachOfSeries, tasks, cb); +} diff --git a/build/es/setImmediate.js b/build/es/setImmediate.js new file mode 100644 index 000000000..05d9555b0 --- /dev/null +++ b/build/es/setImmediate.js @@ -0,0 +1,5 @@ +'use strict'; + +import setImmediate from './internal/setImmediate'; + +export default setImmediate; diff --git a/build/es/some.js b/build/es/some.js new file mode 100644 index 000000000..46532b782 --- /dev/null +++ b/build/es/some.js @@ -0,0 +1,8 @@ +'use strict'; + +import identity from 'lodash-es/identity'; + +import createTester from './internal/createTester'; +import eachOf from './eachOf'; + +export default createTester(eachOf, Boolean, identity); diff --git a/build/es/someLimit.js b/build/es/someLimit.js new file mode 100644 index 000000000..6c1706713 --- /dev/null +++ b/build/es/someLimit.js @@ -0,0 +1,7 @@ +'use strict'; + +import createTester from './internal/createTester'; +import eachOfLimit from './eachOfLimit'; +import identity from 'lodash-es/identity'; + +export default createTester(eachOfLimit, Boolean, identity); diff --git a/build/es/sortBy.js b/build/es/sortBy.js new file mode 100644 index 000000000..b4c8b8ee4 --- /dev/null +++ b/build/es/sortBy.js @@ -0,0 +1,23 @@ +'use strict'; + +import arrayMap from 'lodash-es/internal/arrayMap'; +import property from 'lodash-es/internal/baseProperty'; + +import map from './map'; + +export default function sortBy (arr, iterator, cb) { + map(arr, function (x, cb) { + iterator(x, function (err, criteria) { + if (err) return cb(err); + cb(null, {value: x, criteria: criteria}); + }); + }, function (err, results) { + if (err) return cb(err); + cb(null, arrayMap(results.sort(comparator), property('value'))); + }); + + function comparator(left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + } +} diff --git a/build/es/times.js b/build/es/times.js new file mode 100644 index 000000000..da2b31ff6 --- /dev/null +++ b/build/es/times.js @@ -0,0 +1,8 @@ +'use strict'; + +import map from './map'; +import range from 'lodash-es/internal/baseRange'; + +export default function (count, iterator, callback) { + map(range(0, count, 1), iterator, callback); +} diff --git a/build/es/timesLimit.js b/build/es/timesLimit.js new file mode 100644 index 000000000..9c2fecac1 --- /dev/null +++ b/build/es/timesLimit.js @@ -0,0 +1,8 @@ +'use strict'; + +import mapLimit from './mapLimit'; +import range from 'lodash-es/internal/baseRange'; + +export default function timeLimit(count, limit, iterator, cb) { + return mapLimit(range(0, count, 1), limit, iterator, cb); +} diff --git a/build/es/timesSeries.js b/build/es/timesSeries.js new file mode 100644 index 000000000..ebcb34504 --- /dev/null +++ b/build/es/timesSeries.js @@ -0,0 +1,8 @@ +'use strict'; + +import mapSeries from './mapSeries'; +import range from 'lodash-es/internal/baseRange'; + +export default function (count, iterator, callback) { + mapSeries(range(0, count, 1), iterator, callback); +} diff --git a/build/es/transform.js b/build/es/transform.js new file mode 100644 index 000000000..7b80fcad2 --- /dev/null +++ b/build/es/transform.js @@ -0,0 +1,19 @@ +'use strict'; + +import isArray from 'lodash-es/isArray'; + +import eachOf from './eachOf'; + +export default function transform (arr, memo, iterator, callback) { + if (arguments.length === 3) { + callback = iterator; + iterator = memo; + memo = isArray(arr) ? [] : {}; + } + + eachOf(arr, function(v, k, cb) { + iterator(memo, v, k, cb); + }, function(err) { + callback(err, memo); + }); +} diff --git a/build/es/unmemoize.js b/build/es/unmemoize.js new file mode 100644 index 000000000..d652e7b87 --- /dev/null +++ b/build/es/unmemoize.js @@ -0,0 +1,7 @@ +'use strict'; + +export default function unmemoize(fn) { + return function () { + return (fn.unmemoized || fn).apply(null, arguments); + }; +} diff --git a/build/es/until.js b/build/es/until.js new file mode 100644 index 000000000..f9ed2fd2f --- /dev/null +++ b/build/es/until.js @@ -0,0 +1,9 @@ +'use strict'; + +import whilst from './whilst'; + +export default function until(test, iterator, cb) { + return whilst(function() { + return !test.apply(this, arguments); + }, iterator, cb); +} diff --git a/build/es/waterfall.js b/build/es/waterfall.js new file mode 100644 index 000000000..c629bcf53 --- /dev/null +++ b/build/es/waterfall.js @@ -0,0 +1,32 @@ +'use strict'; + +import isArray from 'lodash-es/isArray'; +import noop from 'lodash-es/noop'; +import once from 'lodash-es/once'; +import rest from 'lodash-es/rest'; + +import ensureAsync from './ensureAsync'; +import iterator from './iterator'; + +export default function(tasks, cb) { + cb = once(cb || noop); + if (!isArray(tasks)) return cb(new Error('First argument to waterfall must be an array of functions')); + if (!tasks.length) return cb(); + + function wrapIterator(iterator) { + return rest(function(err, args) { + if (err) { + cb.apply(null, [err].concat(args)); + } else { + var next = iterator.next(); + if (next) { + args.push(wrapIterator(next)); + } else { + args.push(cb); + } + ensureAsync(iterator).apply(null, args); + } + }); + } + wrapIterator(iterator(tasks))(); +} diff --git a/build/es/whilst.js b/build/es/whilst.js new file mode 100644 index 000000000..2f5c2ef17 --- /dev/null +++ b/build/es/whilst.js @@ -0,0 +1,15 @@ +'use strict'; + +import noop from 'lodash-es/noop'; +import rest from 'lodash-es/rest'; + +export default function whilst(test, iterator, cb) { + cb = cb || noop; + if (!test()) return cb(null); + var next = rest(function(err, args) { + if (err) return cb(err); + if (test.apply(this, args)) return iterator(next); + cb.apply(null, [null].concat(args)); + }); + iterator(next); +} diff --git a/build/package.json b/build/package.json new file mode 100644 index 000000000..2e0b63b28 --- /dev/null +++ b/build/package.json @@ -0,0 +1,97 @@ +{ + "name": "async", + "description": "Higher-order functions and common patterns for asynchronous code", + "version": "2.0.0-alpha", + "main": "index.js", + "esnext:main": "es/index.js", + "author": "Caolan McMahon", + "repository": { + "type": "git", + "url": "https://github.com/caolan/async.git" + }, + "bugs": { + "url": "https://github.com/caolan/async/issues" + }, + "keywords": [ + "async", + "callback", + "module", + "utility" + ], + "dependencies": { + "lodash": "^4.0.0", + "lodash-es": "^4.0.0" + }, + "devDependencies": { + "babel-cli": "^6.3.17", + "babel-core": "^6.3.26", + "babel-plugin-add-module-exports": "~0.1.2", + "babel-plugin-transform-es2015-modules-commonjs": "^6.3.16", + "babel-preset-es2015": "^6.3.13", + "babelify": "^7.2.0", + "benchmark": "bestiejs/benchmark.js", + "bluebird": "^2.9.32", + "chai": "^3.1.0", + "coveralls": "^2.11.2", + "es6-promise": "^2.3.0", + "fs-extra": "^0.26.3", + "gulp": "~3.9.0", + "jscs": "^1.13.1", + "jshint": "~2.8.0", + "karma": "^0.13.2", + "karma-browserify": "^4.2.1", + "karma-firefox-launcher": "^0.1.6", + "karma-mocha": "^0.2.0", + "karma-mocha-reporter": "^1.0.2", + "mocha": "^2.2.5", + "native-promise-only": "^0.8.0-a", + "nodeunit": ">0.0.0", + "nyc": "^2.1.0", + "recursive-readdir": "^1.3.0", + "rimraf": "^2.5.0", + "rollup": "^0.25.0", + "rollup-plugin-npm": "~1.3.0", + "rsvp": "^3.0.18", + "semver": "^4.3.6", + "uglify-js": "~2.4.0", + "vinyl-buffer": "~1.0.0", + "vinyl-source-stream": "~1.1.0", + "xyz": "^0.5.0", + "yargs": "~3.9.1" + }, + "scripts": { + "coverage": "nyc npm test && nyc report", + "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls", + "lint": "jshint lib/ test/ mocha_test/ perf/memory.js perf/suites.js perf/benchmark.js support/ gulpfile.js karma.conf.js && jscs lib/ test/ mocha_test/ perf/memory.js perf/suites.js perf/benchmark.js support/ gulpfile.js karma.conf.js", + "mocha-browser-test": "karma start", + "mocha-node-test": "mocha mocha_test/ --compilers js:babel-core/register", + "mocha-test": "npm run mocha-node-test && npm run mocha-browser-test", + "nodeunit-test": "nodeunit test/test-async.js", + "test": "npm run-script lint && npm run nodeunit-test && npm run mocha-test" + }, + "license": "MIT", + "jam": { + "main": "async.js", + "include": [ + "async.js", + "README.md", + "LICENSE" + ], + "categories": [ + "Utilities" + ] + }, + "spm": { + "main": "async.js" + }, + "volo": { + "main": "async.js", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] + } +} diff --git a/component.json b/component.json index 5b0514974..b699237fc 100644 --- a/component.json +++ b/component.json @@ -1,17 +1,17 @@ { "name": "async", "description": "Higher-order functions and common patterns for asynchronous code", - "version": "1.5.0", + "version": "2.0.0-alpha", "keywords": [ "async", "callback", - "utility", - "module" + "module", + "utility" ], "license": "MIT", - "main": "lib/async.js", + "main": "index.js", "repository": "caolan/async", "scripts": [ - "lib/async.js" + "index.js" ] -} +} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 000000000..0d0b270df --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require("./build/") diff --git a/package.json b/package.json index c0fbf4db4..756ad2b7f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "async", "description": "Higher-order functions and common patterns for asynchronous code", "version": "2.0.0-alpha", - "main": "lib/async.js", + "main": "index.js", + "esnext:main": "es/index.js", "author": "Caolan McMahon", "repository": { "type": "git", @@ -58,11 +59,6 @@ "xyz": "^0.5.0", "yargs": "~3.9.1" }, - "files": [ - "dist/async.js", - "dist/async.min.js", - "lib" - ], "scripts": { "coverage": "nyc npm test && nyc report", "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls", @@ -75,27 +71,27 @@ }, "license": "MIT", "jam": { - "categories": [ - "Utilities" - ], + "main": "index.js", "include": [ - "LICENSE", + "lib/async.js", "README.md", - "lib/async.js" + "LICENSE" ], - "main": "lib/async.js" + "categories": [ + "Utilities" + ] }, "spm": { - "main": "lib/async.js" + "main": "index.js" }, "volo": { + "main": "index.js", "ignore": [ "**/.*", - "bower_components", "node_modules", + "bower_components", "test", "tests" - ], - "main": "lib/async.js" + ] } -} +} \ No newline at end of file From 8a7f8642467222519cc722c3c634036fbc9d9068 Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Tue, 9 Feb 2016 19:35:49 -0800 Subject: [PATCH 20/36] fix lint error --- support/es.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/support/es.test.js b/support/es.test.js index e5acbf82c..3107e137d 100644 --- a/support/es.test.js +++ b/support/es.test.js @@ -8,9 +8,8 @@ waterfall([ constant(42), function (val, next) { async.setImmediate(function () { - console.log("blah"); next(null, val); - }) + }); } ], function (err, result) { if (err) { throw err; } From b001e4a9c3e51bf277d69b54e5776caa7099a455 Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Wed, 10 Feb 2016 15:14:36 -0800 Subject: [PATCH 21/36] handle moved lodash internal methods --- build/async.js | 21 ++++++++++----------- build/async.min.js | 2 +- build/auto.js | 6 +++--- build/es/auto.js | 6 +++--- build/es/internal/consoleFunc.js | 2 +- build/es/internal/filter.js | 4 ++-- build/es/internal/queue.js | 6 +++--- build/es/priorityQueue.js | 2 +- build/es/sortBy.js | 4 ++-- build/es/times.js | 2 +- build/es/timesLimit.js | 2 +- build/es/timesSeries.js | 2 +- build/internal/consoleFunc.js | 2 +- build/internal/filter.js | 4 ++-- build/internal/queue.js | 6 +++--- build/package.json | 12 ++++++------ build/priorityQueue.js | 2 +- build/sortBy.js | 4 ++-- build/times.js | 2 +- build/timesLimit.js | 2 +- build/timesSeries.js | 2 +- index.js | 4 +++- lib/auto.js | 6 +++--- lib/internal/consoleFunc.js | 2 +- lib/internal/filter.js | 4 ++-- lib/internal/queue.js | 6 +++--- lib/priorityQueue.js | 2 +- lib/sortBy.js | 4 ++-- lib/times.js | 2 +- lib/timesLimit.js | 2 +- lib/timesSeries.js | 2 +- package.json | 4 ++-- 32 files changed, 67 insertions(+), 66 deletions(-) diff --git a/build/async.js b/build/async.js index e5d60e308..3fe1422b7 100644 --- a/build/async.js +++ b/build/async.js @@ -11,11 +11,11 @@ * @private * @param {Function} func The function to invoke. * @param {*} thisArg The `this` binding of `func`. - * @param {...*} [args] The arguments to invoke `func` with. + * @param {...*} args The arguments to invoke `func` with. * @returns {*} Returns the result of `func`. */ function apply$1(func, thisArg, args) { - var length = args ? args.length : 0; + var length = args.length; switch (length) { case 0: return func.call(thisArg); case 1: return func.call(thisArg, args[0]); @@ -49,8 +49,6 @@ * // => false */ function isObject(value) { - // Avoid a V8 JIT bug in Chrome 19-20. - // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. var type = typeof value; return !!value && (type == 'object' || type == 'function'); } @@ -642,9 +640,11 @@ */ function indexKeys(object) { var length = object ? object.length : undefined; - return (isLength(length) && (isArray(object) || isString(object) || isArguments(object))) - ? baseTimes(length, String) - : null; + if (isLength(length) && + (isArray(object) || isString(object) || isArguments(object))) { + return baseTimes(length, String); + } + return null; } /** Used as references for various `Number` constants. */ @@ -961,7 +961,7 @@ } /** - * This method returns the first argument provided to it. + * This method returns the first argument given to it. * * @static * @memberOf _ @@ -1073,8 +1073,7 @@ * Gets the index at which the first occurrence of `value` is found in `array` * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. If `fromIndex` is negative, it's used as the offset - * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` - * performs a faster binary search. + * from the end of `array`. * * @static * @memberOf _ @@ -1088,7 +1087,7 @@ * _.indexOf([1, 2, 1, 2], 2); * // => 1 * - * // using `fromIndex` + * // Search from the `fromIndex`. * _.indexOf([1, 2, 1, 2], 2, 2); * // => 3 */ diff --git a/build/async.min.js b/build/async.min.js index ff40154df..1b8ab3b46 100644 --- a/build/async.min.js +++ b/build/async.min.js @@ -1,2 +1,2 @@ -!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.async={})}(this,function(n){"use strict";function t(n,t,r){var e=r?r.length:0;switch(e){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function r(n){var t=typeof n;return!!n&&("object"==t||"function"==t)}function e(n){var t=r(n)?Hn.call(n):"";return t==Un||t==Cn}function u(n){if(r(n)){var t=e(n.valueOf)?n.valueOf():n;n=r(t)?t+"":t}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(Qn,"");var u=Wn.test(n);return u||Gn.test(n)?Jn(n.slice(2),u?2:8):Rn.test(n)?Nn:+n}function i(n){if(!n)return 0===n?n:0;if(n=u(n),n===Kn||n===-Kn){var t=0>n?-1:1;return t*Vn}var r=n%1;return n===n?r?n-r:n:0}function o(n,r){if("function"!=typeof n)throw new TypeError(Xn);return r=Yn(void 0===r?n.length-1:i(r),0),function(){for(var e=arguments,u=-1,i=Yn(e.length-r,0),o=Array(i);++u0&&(r=t.apply(this,arguments)),1>=n&&(t=void 0),r}}function f(n){return a(2,n)}function l(){}function s(n){return function(t){return null==t?void 0:t[n]}}function p(n){return"number"==typeof n&&n>-1&&n%1==0&&nt>=n}function h(n){return null!=n&&!("function"==typeof n&&e(n))&&p(_n(n))}function y(n,t){return rt.call(n,t)||"object"==typeof n&&t in n&&null===et(n)}function m(n){return ut(Object(n))}function v(n,t){for(var r=-1,e=Array(n);++r-1&&n%1==0&&t>n}function S(n){var t=n&&n.constructor,r="function"==typeof t&&t.prototype||vt;return n===r}function j(n){var t=S(n);if(!t&&!h(n))return m(n);var r=w(n),e=!!r,u=r||[],i=u.length;for(var o in n)!y(n,o)||e&&("length"==o||E(o,i))||t&&"constructor"==o||u.push(o);return u}function L(n){var t,r=-1;if(h(n))return t=n.length,function(){return r++,t>r?r:null};var e=j(n);return t=e.length,function(){return r++,t>r?e[r]:null}}function O(n){return function(){if(null===n)throw new Error("Callback was already called.");n.apply(this,arguments),n=null}}function x(n,t,r){function e(n){o--,n?r(n):null===u&&0>=o&&r(null)}r=f(r||l),n=n||[];for(var u,i=L(n),o=0;null!=(u=i());)o+=1,t(n[u],u,O(e));0===o&&r(null)}function A(n,t,r){function e(){var o=!0;return null===i?r(null):(t(n[i],i,O(function(n){if(n)r(n);else{if(i=u(),null===i)return r(null);o?kt(e):e()}})),void(o=!1))}r=f(r||l),n=n||[];var u=L(n),i=u();e()}function I(n){return o(function(t){var e,u=t.pop();try{e=n.apply(this,t)}catch(i){return u(i)}r(e)&&"function"==typeof e.then?e.then(function(n){u(null,n)})["catch"](function(n){u(n.message?n:new Error(n))}):u(null,e)})}function T(n,t){for(var r=-1,e=n.length;++rr&&(r=St(e+r,0)),U(n,t,r)):-1}function D(n,t,r){function e(n){h.unshift(n)}function u(n){var t=C(h,n);t>=0&&h.splice(t,1)}function i(){a--,T(h.slice(),function(n){n()})}"function"==typeof arguments[1]&&(r=t,t=null),r=f(r||l);var c=j(n),a=c.length;if(!a)return r(null);t||(t=a);var s={},p=0,h=[];e(function(){a||r(null,s)}),T(c,function(c){function a(){return t>p&&!y(s,c)&&z(v,function(n){return y(s,n)})}function f(){a()&&(p++,u(f),h[h.length-1](m,s))}for(var l,h=lt(n[c])?n[c]:[n[c]],m=o(function(n,t){if(p--,t.length<=1&&(t=t[0]),n){var e={};F(s,function(n,t){e[t]=n}),e[c]=t,r(n,e)}else s[c]=t,kt(i)}),v=h.slice(0,h.length-1),d=v.length;d--;){if(!(l=n[v[d]]))throw new Error("Has inexistant dependency");if(lt(l)&&C(l,c)>=0)throw new Error("Has cyclic dependencies")}a()?(p++,h[h.length-1](m,s)):e(f)})}function H(n,t){for(var r=-1,e=n.length,u=Array(e);++r=t;t++)kt(c.process)}}};return c}function Q(n,t){return N(n,1,t)}function R(n,t,r,e){A(n,function(n,e,u){r(t,n,function(n,r){t=r,u(n)})},function(n){e(n,t)})}function W(){var n=arguments;return o(function(t){var r=this,e=t[t.length-1];"function"==typeof e?t.pop():e=l,R(n,t,function(n,t,e){t.apply(r,n.concat([o(function(n,t){e(n,t)})]))},function(n,t){e.apply(r,[n].concat(t))})})}function G(){return W.apply(null,jt.call(arguments))}function J(n,t,r,e){var u=[];n(t,function(n,t,e){r(n,function(n,t){u=u.concat(t||[]),e(n)})},function(n){e(n,u)})}function K(n){return function(t,r,e){return n(x,t,r,e)}}function V(n){return function(t,r,e){return n(A,t,r,e)}}function X(n,t,r){return function(e,u,i,o){function c(){o&&o(r(!1,void 0))}function a(n,e,u){return o?void i(n,function(e){o&&t(e)&&(o(r(!0,n)),o=i=!1),u()}):u()}arguments.length>3?n(e,u,a,c):(o=i,i=u,n(e,a,c))}}function Y(n,t){return t}function Z(n){return function(t,r,e){e=f(e||l),t=t||[];var u=L(t);if(0>=n)return e(null);var i=!1,o=0,c=!1;!function a(){if(i&&0>=o)return e(null);for(;n>o&&!c;){var f=u();if(null===f)return i=!0,void(0>=o&&e(null));o+=1,r(t[f],f,O(function(n){o-=1,n?(e(n),c=!0):a()}))}}()}}function _(n,t,r,e){Z(t)(n,r,e)}function nn(n){return o(function(t,r){t.apply(null,r.concat([o(function(t,r){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&T(r,function(t){console[n](t)}))})]))})}function tn(n,t,r){r=r||l;var e=o(function(t,e){t?r(t):(e.push(u),n.apply(this,e))}),u=function(n,u){return n?r(n):u?void t(e):r(null)};n(u)}function rn(n,t,r){var e=0;tn(function(n){return e++<1?n(null,!0):void t.apply(this,arguments)},n,r)}function en(n,t,r){if(r=r||l,!n())return r(null);var e=o(function(u,i){return u?r(u):n.apply(this,i)?t(e):void r.apply(null,[null].concat(i))});t(e)}function un(n,t,r){var e=0;return en(function(){return++e<=1||t.apply(this,arguments)},n,r)}function on(n,t,r){return un(n,function(){return!t.apply(this,arguments)},r)}function cn(n){return function(t,r,e){return n(t,e)}}function an(n,t,r){return x(n,cn(t),r)}function fn(n,t,r,e){return Z(t)(n,cn(r),e)}function ln(n,t,r){return A(n,cn(t),r)}function sn(n){return o(function(t){var r=t.pop(),e=!0;t.push(function(){var n=arguments;e?kt(function(){r.apply(null,n)}):r.apply(null,n)}),n.apply(this,t),e=!1})}function pn(n){return!n}function hn(n,t,r,e){var u=[];n(t,function(n,t,e){r(n,function(r){r&&u.push({index:t,value:n}),e()})},function(){e(H(u.sort(function(n,t){return n.index-t.index}),s("value")))})}function yn(n){return function(t,r,e,u){return n(Z(r),t,e,u)}}function mn(n,t){function r(n){return n?e(n):void u(r)}var e=O(t||l),u=sn(n);r()}function vn(n){function t(r){function e(){return n.length&&n[r].apply(null,arguments),e.next()}return e.next=function(){return ru;u++)t[u].apply(null,n)})])))});return u.memo=r,u.unmemoized=n,u}function kn(n,t,r){r=r||l;var e=h(t)?[]:{};n(t,function(n,t,r){n(o(function(n,u){u.length<=1&&(u=u[0]),e[t]=u,r(n)}))},function(n){r(n,e)})}function bn(n,t){return kn(x,n,t)}function wn(n,t,r){return kn(Z(t),n,r)}function En(n,t){return N(function(t,r){n(t[0],r)},t,1)}function Sn(n,t){function r(n,t){return n.priority-t.priority}function e(n,t,r){for(var e=-1,u=n.length-1;u>e;){var i=e+(u-e+1>>>1);r(t,n[i])>=0?e=i:u=i-1}return e}function u(n,t,u,i){if(null!=i&&"function"!=typeof i)throw new Error("task callback must be a function");return n.started=!0,lt(t)||(t=[t]),0===t.length?kt(function(){n.drain()}):void T(t,function(t){var o={data:t,priority:u,callback:"function"==typeof i?i:l};n.tasks.splice(e(n.tasks,o,r)+1,0,o),n.tasks.length===n.concurrency&&n.saturated(),kt(n.process)})}var i=En(n,t);return i.push=function(n,t,r){u(i,n,t,r)},delete i.unshift,i}function jn(n,t,r,e){var u=Nt.call(n).reverse();R(u,t,r,e)}function Ln(n,t,r,e){hn(n,t,function(n,t){r(n,function(n){t(!n)})},e)}function On(n,t){return kn(A,n,t)}function xn(n,t,r){function e(n,t){if("number"==typeof t)n.times=parseInt(t,10)||i;else{if("object"!=typeof t)throw new Error("Unsupported argument type for 'times': "+typeof t);n.times=parseInt(t.times,10)||i,n.interval=parseInt(t.interval,10)||o}}function u(n,t){function r(n,r){return function(e){n(function(n,t){e(!n||r,{err:n,result:t})},t)}}function e(n){return function(t){setTimeout(function(){t(null)},n)}}for(;a.times;){var u=!(a.times-=1);c.push(r(a.task,u)),!u&&a.interval>0&&c.push(e(a.interval))}On(c,function(t,r){r=r[r.length-1],(n||a.callback)(r.err,r.result)})}var i=5,o=0,c=[],a={times:i,interval:o},f=arguments.length;if(1>f||f>3)throw new Error("Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)");return 2>=f&&"function"==typeof n&&(r=t,t=n),"function"!=typeof n&&e(a,n),a.callback=r,a.task=t,a.callback?u():u}function An(n,t,r){function e(n,t){var r=n.criteria,e=t.criteria;return e>r?-1:r>e?1:0}Ut(n,function(n,r){t(n,function(t,e){return t?r(t):void r(null,{value:n,criteria:e})})},function(n,t){return n?r(n):void r(null,H(t.sort(e),s("value")))})}function In(n,t,r,e){for(var u=-1,i=Vt(Kt((t-n)/(r||1)),0),o=Array(i);i--;)o[e?i:++u]=n,n+=r;return o}function Tn(n,t,r){Ut(In(0,n,1),t,r)}function zn(n,t,r,e){return Ct(In(0,n,1),t,r,e)}function Mn(n,t,r){Dt(In(0,n,1),t,r)}function $n(n,t,r,e){3===arguments.length&&(e=r,r=t,t=lt(n)?[]:{}),x(n,function(n,e,u){r(t,n,e,u)},function(n){e(n,t)})}function qn(n){return function(){return(n.unmemoized||n).apply(null,arguments)}}function Bn(n,t,r){return en(function(){return!n.apply(this,arguments)},t,r)}function Fn(n,t){function r(n){return o(function(e,u){if(e)t.apply(null,[e].concat(u));else{var i=n.next();i?u.push(r(i)):u.push(t),sn(n).apply(null,u)}})}return t=f(t||l),lt(n)?n.length?void r(vn(n))():t():t(new Error("First argument to waterfall must be an array of functions"))}var Pn,Un="[object Function]",Cn="[object GeneratorFunction]",Dn=Object.prototype,Hn=Dn.toString,Nn=NaN,Qn=/^\s+|\s+$/g,Rn=/^[-+]0x[0-9a-f]+$/i,Wn=/^0b[01]+$/i,Gn=/^0o[0-7]+$/i,Jn=parseInt,Kn=1/0,Vn=1.7976931348623157e308,Xn="Expected a function",Yn=Math.max,Zn="Expected a function",_n=s("length"),nt=9007199254740991,tt=Object.prototype,rt=tt.hasOwnProperty,et=Object.getPrototypeOf,ut=Object.keys,it="[object Arguments]",ot=Object.prototype,ct=ot.hasOwnProperty,at=ot.toString,ft=ot.propertyIsEnumerable,lt=Array.isArray,st="[object String]",pt=Object.prototype,ht=pt.toString,yt=9007199254740991,mt=/^(?:0|[1-9]\d*)$/,vt=Object.prototype,dt=c(x),gt="function"==typeof setImmediate&&setImmediate;Pn=gt?function(n){gt(n)}:"object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:function(n){setTimeout(n,0)};var kt=Pn,bt=c(A),wt=o(function(n,t){return o(function(r){return n.apply(null,t.concat(r))})}),Et=M(),St=Math.max,jt=Array.prototype.reverse,Lt=K(J),Ot=V(J),xt=o(function(n){var t=[null].concat(n);return function(n){return n.apply(this,t)}}),At=X(x,q,Y),It=X(_,q,Y),Tt=X(A,q,Y),zt=nn("dir"),Mt=X(x,pn,pn),$t=X(_,pn,pn),qt=K(hn),Bt=yn(hn),Ft=V(hn),Pt=nn("log"),Ut=K(dn),Ct=yn(dn),Dt=V(dn),Ht="object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:kt,Nt=Array.prototype.slice,Qt=K(Ln),Rt=yn(Ln),Wt=V(Ln),Gt=X(x,Boolean,q),Jt=X(_,Boolean,q),Kt=Math.ceil,Vt=Math.max,Xt={applyEach:dt,applyEachSeries:bt,apply:wt,asyncify:I,auto:D,cargo:Q,compose:G,concat:Lt,concatSeries:Ot,constant:xt,detect:At,detectLimit:It,detectSeries:Tt,dir:zt,doDuring:rn,doUntil:on,doWhilst:un,during:tn,each:an,eachLimit:fn,eachOf:x,eachOfLimit:_,eachOfSeries:A,eachSeries:ln,ensureAsync:sn,every:Mt,everyLimit:$t,filter:qt,filterLimit:Bt,filterSeries:Ft,forever:mn,iterator:vn,log:Pt,map:Ut,mapLimit:Ct,mapSeries:Dt,memoize:gn,nextTick:Ht,parallel:bn,parallelLimit:wn,priorityQueue:Sn,queue:En,reduce:R,reduceRight:jn,reject:Qt,rejectLimit:Rt,rejectSeries:Wt,retry:xn,seq:W,series:On,setImmediate:kt,some:Gt,someLimit:Jt,sortBy:An,times:Tn,timesLimit:zn,timesSeries:Mn,transform:$n,unmemoize:qn,until:Bn,waterfall:Fn,whilst:en,all:Mt,any:Gt,forEach:an,forEachSeries:ln,forEachLimit:fn,forEachOf:x,forEachOfSeries:A,forEachOfLimit:_,inject:R,foldl:R,foldr:jn,select:qt,selectLimit:Bt,selectSeries:Ft,wrapSync:I};n["default"]=Xt,n.applyEach=dt,n.applyEachSeries=bt,n.apply=wt,n.asyncify=I,n.auto=D,n.cargo=Q,n.compose=G,n.concat=Lt,n.concatSeries=Ot,n.constant=xt,n.detect=At,n.detectLimit=It,n.detectSeries=Tt,n.dir=zt,n.doDuring=rn,n.doUntil=on,n.doWhilst=un,n.during=tn,n.each=an,n.eachLimit=fn,n.eachOf=x,n.eachOfLimit=_,n.eachOfSeries=A,n.eachSeries=ln,n.ensureAsync=sn,n.every=Mt,n.everyLimit=$t,n.filter=qt,n.filterLimit=Bt,n.filterSeries=Ft,n.forever=mn,n.iterator=vn,n.log=Pt,n.map=Ut,n.mapLimit=Ct,n.mapSeries=Dt,n.memoize=gn,n.nextTick=Ht,n.parallel=bn,n.parallelLimit=wn,n.priorityQueue=Sn,n.queue=En,n.reduce=R,n.reduceRight=jn,n.reject=Qt,n.rejectLimit=Rt,n.rejectSeries=Wt,n.retry=xn,n.seq=W,n.series=On,n.setImmediate=kt,n.some=Gt,n.someLimit=Jt,n.sortBy=An,n.times=Tn,n.timesLimit=zn,n.timesSeries=Mn,n.transform=$n,n.unmemoize=qn,n.until=Bn,n.waterfall=Fn,n.whilst=en,n.all=Mt,n.any=Gt,n.forEach=an,n.forEachSeries=ln,n.forEachLimit=fn,n.forEachOf=x,n.forEachOfSeries=A,n.forEachOfLimit=_,n.inject=R,n.foldl=R,n.foldr=jn,n.select=qt,n.selectLimit=Bt,n.selectSeries=Ft,n.wrapSync=I}); +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.async={})}(this,function(n){"use strict";function t(n,t,r){var e=r.length;switch(e){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function r(n){var t=typeof n;return!!n&&("object"==t||"function"==t)}function e(n){var t=r(n)?Hn.call(n):"";return t==Un||t==Cn}function u(n){if(r(n)){var t=e(n.valueOf)?n.valueOf():n;n=r(t)?t+"":t}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(Qn,"");var u=Wn.test(n);return u||Gn.test(n)?Jn(n.slice(2),u?2:8):Rn.test(n)?Nn:+n}function i(n){if(!n)return 0===n?n:0;if(n=u(n),n===Kn||n===-Kn){var t=0>n?-1:1;return t*Vn}var r=n%1;return n===n?r?n-r:n:0}function o(n,r){if("function"!=typeof n)throw new TypeError(Xn);return r=Yn(void 0===r?n.length-1:i(r),0),function(){for(var e=arguments,u=-1,i=Yn(e.length-r,0),o=Array(i);++u0&&(r=t.apply(this,arguments)),1>=n&&(t=void 0),r}}function f(n){return a(2,n)}function l(){}function s(n){return function(t){return null==t?void 0:t[n]}}function p(n){return"number"==typeof n&&n>-1&&n%1==0&&nt>=n}function h(n){return null!=n&&!("function"==typeof n&&e(n))&&p(_n(n))}function y(n,t){return rt.call(n,t)||"object"==typeof n&&t in n&&null===et(n)}function m(n){return ut(Object(n))}function v(n,t){for(var r=-1,e=Array(n);++r-1&&n%1==0&&t>n}function S(n){var t=n&&n.constructor,r="function"==typeof t&&t.prototype||vt;return n===r}function j(n){var t=S(n);if(!t&&!h(n))return m(n);var r=w(n),e=!!r,u=r||[],i=u.length;for(var o in n)!y(n,o)||e&&("length"==o||E(o,i))||t&&"constructor"==o||u.push(o);return u}function L(n){var t,r=-1;if(h(n))return t=n.length,function(){return r++,t>r?r:null};var e=j(n);return t=e.length,function(){return r++,t>r?e[r]:null}}function O(n){return function(){if(null===n)throw new Error("Callback was already called.");n.apply(this,arguments),n=null}}function x(n,t,r){function e(n){o--,n?r(n):null===u&&0>=o&&r(null)}r=f(r||l),n=n||[];for(var u,i=L(n),o=0;null!=(u=i());)o+=1,t(n[u],u,O(e));0===o&&r(null)}function A(n,t,r){function e(){var o=!0;return null===i?r(null):(t(n[i],i,O(function(n){if(n)r(n);else{if(i=u(),null===i)return r(null);o?kt(e):e()}})),void(o=!1))}r=f(r||l),n=n||[];var u=L(n),i=u();e()}function I(n){return o(function(t){var e,u=t.pop();try{e=n.apply(this,t)}catch(i){return u(i)}r(e)&&"function"==typeof e.then?e.then(function(n){u(null,n)})["catch"](function(n){u(n.message?n:new Error(n))}):u(null,e)})}function T(n,t){for(var r=-1,e=n.length;++rr&&(r=St(e+r,0)),U(n,t,r)):-1}function D(n,t,r){function e(n){h.unshift(n)}function u(n){var t=C(h,n);t>=0&&h.splice(t,1)}function i(){a--,T(h.slice(),function(n){n()})}"function"==typeof arguments[1]&&(r=t,t=null),r=f(r||l);var c=j(n),a=c.length;if(!a)return r(null);t||(t=a);var s={},p=0,h=[];e(function(){a||r(null,s)}),T(c,function(c){function a(){return t>p&&!y(s,c)&&z(v,function(n){return y(s,n)})}function f(){a()&&(p++,u(f),h[h.length-1](m,s))}for(var l,h=lt(n[c])?n[c]:[n[c]],m=o(function(n,t){if(p--,t.length<=1&&(t=t[0]),n){var e={};F(s,function(n,t){e[t]=n}),e[c]=t,r(n,e)}else s[c]=t,kt(i)}),v=h.slice(0,h.length-1),d=v.length;d--;){if(!(l=n[v[d]]))throw new Error("Has inexistant dependency");if(lt(l)&&C(l,c)>=0)throw new Error("Has cyclic dependencies")}a()?(p++,h[h.length-1](m,s)):e(f)})}function H(n,t){for(var r=-1,e=n.length,u=Array(e);++r=t;t++)kt(c.process)}}};return c}function Q(n,t){return N(n,1,t)}function R(n,t,r,e){A(n,function(n,e,u){r(t,n,function(n,r){t=r,u(n)})},function(n){e(n,t)})}function W(){var n=arguments;return o(function(t){var r=this,e=t[t.length-1];"function"==typeof e?t.pop():e=l,R(n,t,function(n,t,e){t.apply(r,n.concat([o(function(n,t){e(n,t)})]))},function(n,t){e.apply(r,[n].concat(t))})})}function G(){return W.apply(null,jt.call(arguments))}function J(n,t,r,e){var u=[];n(t,function(n,t,e){r(n,function(n,t){u=u.concat(t||[]),e(n)})},function(n){e(n,u)})}function K(n){return function(t,r,e){return n(x,t,r,e)}}function V(n){return function(t,r,e){return n(A,t,r,e)}}function X(n,t,r){return function(e,u,i,o){function c(){o&&o(r(!1,void 0))}function a(n,e,u){return o?void i(n,function(e){o&&t(e)&&(o(r(!0,n)),o=i=!1),u()}):u()}arguments.length>3?n(e,u,a,c):(o=i,i=u,n(e,a,c))}}function Y(n,t){return t}function Z(n){return function(t,r,e){e=f(e||l),t=t||[];var u=L(t);if(0>=n)return e(null);var i=!1,o=0,c=!1;!function a(){if(i&&0>=o)return e(null);for(;n>o&&!c;){var f=u();if(null===f)return i=!0,void(0>=o&&e(null));o+=1,r(t[f],f,O(function(n){o-=1,n?(e(n),c=!0):a()}))}}()}}function _(n,t,r,e){Z(t)(n,r,e)}function nn(n){return o(function(t,r){t.apply(null,r.concat([o(function(t,r){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&T(r,function(t){console[n](t)}))})]))})}function tn(n,t,r){r=r||l;var e=o(function(t,e){t?r(t):(e.push(u),n.apply(this,e))}),u=function(n,u){return n?r(n):u?void t(e):r(null)};n(u)}function rn(n,t,r){var e=0;tn(function(n){return e++<1?n(null,!0):void t.apply(this,arguments)},n,r)}function en(n,t,r){if(r=r||l,!n())return r(null);var e=o(function(u,i){return u?r(u):n.apply(this,i)?t(e):void r.apply(null,[null].concat(i))});t(e)}function un(n,t,r){var e=0;return en(function(){return++e<=1||t.apply(this,arguments)},n,r)}function on(n,t,r){return un(n,function(){return!t.apply(this,arguments)},r)}function cn(n){return function(t,r,e){return n(t,e)}}function an(n,t,r){return x(n,cn(t),r)}function fn(n,t,r,e){return Z(t)(n,cn(r),e)}function ln(n,t,r){return A(n,cn(t),r)}function sn(n){return o(function(t){var r=t.pop(),e=!0;t.push(function(){var n=arguments;e?kt(function(){r.apply(null,n)}):r.apply(null,n)}),n.apply(this,t),e=!1})}function pn(n){return!n}function hn(n,t,r,e){var u=[];n(t,function(n,t,e){r(n,function(r){r&&u.push({index:t,value:n}),e()})},function(){e(H(u.sort(function(n,t){return n.index-t.index}),s("value")))})}function yn(n){return function(t,r,e,u){return n(Z(r),t,e,u)}}function mn(n,t){function r(n){return n?e(n):void u(r)}var e=O(t||l),u=sn(n);r()}function vn(n){function t(r){function e(){return n.length&&n[r].apply(null,arguments),e.next()}return e.next=function(){return ru;u++)t[u].apply(null,n)})])))});return u.memo=r,u.unmemoized=n,u}function kn(n,t,r){r=r||l;var e=h(t)?[]:{};n(t,function(n,t,r){n(o(function(n,u){u.length<=1&&(u=u[0]),e[t]=u,r(n)}))},function(n){r(n,e)})}function bn(n,t){return kn(x,n,t)}function wn(n,t,r){return kn(Z(t),n,r)}function En(n,t){return N(function(t,r){n(t[0],r)},t,1)}function Sn(n,t){function r(n,t){return n.priority-t.priority}function e(n,t,r){for(var e=-1,u=n.length-1;u>e;){var i=e+(u-e+1>>>1);r(t,n[i])>=0?e=i:u=i-1}return e}function u(n,t,u,i){if(null!=i&&"function"!=typeof i)throw new Error("task callback must be a function");return n.started=!0,lt(t)||(t=[t]),0===t.length?kt(function(){n.drain()}):void T(t,function(t){var o={data:t,priority:u,callback:"function"==typeof i?i:l};n.tasks.splice(e(n.tasks,o,r)+1,0,o),n.tasks.length===n.concurrency&&n.saturated(),kt(n.process)})}var i=En(n,t);return i.push=function(n,t,r){u(i,n,t,r)},delete i.unshift,i}function jn(n,t,r,e){var u=Nt.call(n).reverse();R(u,t,r,e)}function Ln(n,t,r,e){hn(n,t,function(n,t){r(n,function(n){t(!n)})},e)}function On(n,t){return kn(A,n,t)}function xn(n,t,r){function e(n,t){if("number"==typeof t)n.times=parseInt(t,10)||i;else{if("object"!=typeof t)throw new Error("Unsupported argument type for 'times': "+typeof t);n.times=parseInt(t.times,10)||i,n.interval=parseInt(t.interval,10)||o}}function u(n,t){function r(n,r){return function(e){n(function(n,t){e(!n||r,{err:n,result:t})},t)}}function e(n){return function(t){setTimeout(function(){t(null)},n)}}for(;a.times;){var u=!(a.times-=1);c.push(r(a.task,u)),!u&&a.interval>0&&c.push(e(a.interval))}On(c,function(t,r){r=r[r.length-1],(n||a.callback)(r.err,r.result)})}var i=5,o=0,c=[],a={times:i,interval:o},f=arguments.length;if(1>f||f>3)throw new Error("Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)");return 2>=f&&"function"==typeof n&&(r=t,t=n),"function"!=typeof n&&e(a,n),a.callback=r,a.task=t,a.callback?u():u}function An(n,t,r){function e(n,t){var r=n.criteria,e=t.criteria;return e>r?-1:r>e?1:0}Ut(n,function(n,r){t(n,function(t,e){return t?r(t):void r(null,{value:n,criteria:e})})},function(n,t){return n?r(n):void r(null,H(t.sort(e),s("value")))})}function In(n,t,r,e){for(var u=-1,i=Vt(Kt((t-n)/(r||1)),0),o=Array(i);i--;)o[e?i:++u]=n,n+=r;return o}function Tn(n,t,r){Ut(In(0,n,1),t,r)}function zn(n,t,r,e){return Ct(In(0,n,1),t,r,e)}function Mn(n,t,r){Dt(In(0,n,1),t,r)}function $n(n,t,r,e){3===arguments.length&&(e=r,r=t,t=lt(n)?[]:{}),x(n,function(n,e,u){r(t,n,e,u)},function(n){e(n,t)})}function qn(n){return function(){return(n.unmemoized||n).apply(null,arguments)}}function Bn(n,t,r){return en(function(){return!n.apply(this,arguments)},t,r)}function Fn(n,t){function r(n){return o(function(e,u){if(e)t.apply(null,[e].concat(u));else{var i=n.next();i?u.push(r(i)):u.push(t),sn(n).apply(null,u)}})}return t=f(t||l),lt(n)?n.length?void r(vn(n))():t():t(new Error("First argument to waterfall must be an array of functions"))}var Pn,Un="[object Function]",Cn="[object GeneratorFunction]",Dn=Object.prototype,Hn=Dn.toString,Nn=NaN,Qn=/^\s+|\s+$/g,Rn=/^[-+]0x[0-9a-f]+$/i,Wn=/^0b[01]+$/i,Gn=/^0o[0-7]+$/i,Jn=parseInt,Kn=1/0,Vn=1.7976931348623157e308,Xn="Expected a function",Yn=Math.max,Zn="Expected a function",_n=s("length"),nt=9007199254740991,tt=Object.prototype,rt=tt.hasOwnProperty,et=Object.getPrototypeOf,ut=Object.keys,it="[object Arguments]",ot=Object.prototype,ct=ot.hasOwnProperty,at=ot.toString,ft=ot.propertyIsEnumerable,lt=Array.isArray,st="[object String]",pt=Object.prototype,ht=pt.toString,yt=9007199254740991,mt=/^(?:0|[1-9]\d*)$/,vt=Object.prototype,dt=c(x),gt="function"==typeof setImmediate&&setImmediate;Pn=gt?function(n){gt(n)}:"object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:function(n){setTimeout(n,0)};var kt=Pn,bt=c(A),wt=o(function(n,t){return o(function(r){return n.apply(null,t.concat(r))})}),Et=M(),St=Math.max,jt=Array.prototype.reverse,Lt=K(J),Ot=V(J),xt=o(function(n){var t=[null].concat(n);return function(n){return n.apply(this,t)}}),At=X(x,q,Y),It=X(_,q,Y),Tt=X(A,q,Y),zt=nn("dir"),Mt=X(x,pn,pn),$t=X(_,pn,pn),qt=K(hn),Bt=yn(hn),Ft=V(hn),Pt=nn("log"),Ut=K(dn),Ct=yn(dn),Dt=V(dn),Ht="object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:kt,Nt=Array.prototype.slice,Qt=K(Ln),Rt=yn(Ln),Wt=V(Ln),Gt=X(x,Boolean,q),Jt=X(_,Boolean,q),Kt=Math.ceil,Vt=Math.max,Xt={applyEach:dt,applyEachSeries:bt,apply:wt,asyncify:I,auto:D,cargo:Q,compose:G,concat:Lt,concatSeries:Ot,constant:xt,detect:At,detectLimit:It,detectSeries:Tt,dir:zt,doDuring:rn,doUntil:on,doWhilst:un,during:tn,each:an,eachLimit:fn,eachOf:x,eachOfLimit:_,eachOfSeries:A,eachSeries:ln,ensureAsync:sn,every:Mt,everyLimit:$t,filter:qt,filterLimit:Bt,filterSeries:Ft,forever:mn,iterator:vn,log:Pt,map:Ut,mapLimit:Ct,mapSeries:Dt,memoize:gn,nextTick:Ht,parallel:bn,parallelLimit:wn,priorityQueue:Sn,queue:En,reduce:R,reduceRight:jn,reject:Qt,rejectLimit:Rt,rejectSeries:Wt,retry:xn,seq:W,series:On,setImmediate:kt,some:Gt,someLimit:Jt,sortBy:An,times:Tn,timesLimit:zn,timesSeries:Mn,transform:$n,unmemoize:qn,until:Bn,waterfall:Fn,whilst:en,all:Mt,any:Gt,forEach:an,forEachSeries:ln,forEachLimit:fn,forEachOf:x,forEachOfSeries:A,forEachOfLimit:_,inject:R,foldl:R,foldr:jn,select:qt,selectLimit:Bt,selectSeries:Ft,wrapSync:I};n["default"]=Xt,n.applyEach=dt,n.applyEachSeries=bt,n.apply=wt,n.asyncify=I,n.auto=D,n.cargo=Q,n.compose=G,n.concat=Lt,n.concatSeries=Ot,n.constant=xt,n.detect=At,n.detectLimit=It,n.detectSeries=Tt,n.dir=zt,n.doDuring=rn,n.doUntil=on,n.doWhilst=un,n.during=tn,n.each=an,n.eachLimit=fn,n.eachOf=x,n.eachOfLimit=_,n.eachOfSeries=A,n.eachSeries=ln,n.ensureAsync=sn,n.every=Mt,n.everyLimit=$t,n.filter=qt,n.filterLimit=Bt,n.filterSeries=Ft,n.forever=mn,n.iterator=vn,n.log=Pt,n.map=Ut,n.mapLimit=Ct,n.mapSeries=Dt,n.memoize=gn,n.nextTick=Ht,n.parallel=bn,n.parallelLimit=wn,n.priorityQueue=Sn,n.queue=En,n.reduce=R,n.reduceRight=jn,n.reject=Qt,n.rejectLimit=Rt,n.rejectSeries=Wt,n.retry=xn,n.seq=W,n.series=On,n.setImmediate=kt,n.some=Gt,n.someLimit=Jt,n.sortBy=An,n.times=Tn,n.timesLimit=zn,n.timesSeries=Mn,n.transform=$n,n.unmemoize=qn,n.until=Bn,n.waterfall=Fn,n.whilst=en,n.all=Mt,n.any=Gt,n.forEach=an,n.forEachSeries=ln,n.forEachLimit=fn,n.forEachOf=x,n.forEachOfSeries=A,n.forEachOfLimit=_,n.inject=R,n.foldl=R,n.foldr=jn,n.select=qt,n.selectLimit=Bt,n.selectSeries=Ft,n.wrapSync=I}); //# sourceMappingURL=dist/async.min.map \ No newline at end of file diff --git a/build/auto.js b/build/auto.js index 37a357523..51f7d100e 100644 --- a/build/auto.js +++ b/build/auto.js @@ -96,15 +96,15 @@ exports.default = function (tasks, concurrency, callback) { }); }; -var _arrayEach = require('lodash/internal/arrayEach'); +var _arrayEach = require('lodash/_arrayEach'); var _arrayEach2 = _interopRequireDefault(_arrayEach); -var _arrayEvery = require('lodash/internal/arrayEvery'); +var _arrayEvery = require('lodash/_arrayEvery'); var _arrayEvery2 = _interopRequireDefault(_arrayEvery); -var _baseHas = require('lodash/internal/baseHas'); +var _baseHas = require('lodash/_baseHas'); var _baseHas2 = _interopRequireDefault(_baseHas); diff --git a/build/es/auto.js b/build/es/auto.js index 19f4215f2..8b01ac53e 100644 --- a/build/es/auto.js +++ b/build/es/auto.js @@ -1,8 +1,8 @@ 'use strict'; -import arrayEach from 'lodash-es/internal/arrayEach'; -import arrayEvery from 'lodash-es/internal/arrayEvery'; -import baseHas from 'lodash-es/internal/baseHas'; +import arrayEach from 'lodash-es/_arrayEach'; +import arrayEvery from 'lodash-es/_arrayEvery'; +import baseHas from 'lodash-es/_baseHas'; import forOwn from 'lodash-es/forOwn'; import indexOf from 'lodash-es/indexOf'; import isArray from 'lodash-es/isArray'; diff --git a/build/es/internal/consoleFunc.js b/build/es/internal/consoleFunc.js index 7796d876e..d56a7bd44 100644 --- a/build/es/internal/consoleFunc.js +++ b/build/es/internal/consoleFunc.js @@ -1,6 +1,6 @@ 'use strict'; -import arrayEach from 'lodash-es/internal/arrayEach'; +import arrayEach from 'lodash-es/_arrayEach'; import rest from 'lodash-es/rest'; export default function consoleFunc(name) { diff --git a/build/es/internal/filter.js b/build/es/internal/filter.js index f58eb5226..62932a0e2 100644 --- a/build/es/internal/filter.js +++ b/build/es/internal/filter.js @@ -1,7 +1,7 @@ 'use strict'; -import arrayMap from 'lodash-es/internal/arrayMap'; -import property from 'lodash-es/internal/baseProperty'; +import arrayMap from 'lodash-es/_arrayMap'; +import property from 'lodash-es/_baseProperty'; export default function _filter(eachfn, arr, iterator, callback) { var results = []; diff --git a/build/es/internal/queue.js b/build/es/internal/queue.js index 2e291e30f..e15229bbf 100644 --- a/build/es/internal/queue.js +++ b/build/es/internal/queue.js @@ -1,10 +1,10 @@ 'use strict'; -import arrayEach from 'lodash-es/internal/arrayEach'; -import arrayMap from 'lodash-es/internal/arrayMap'; +import arrayEach from 'lodash-es/_arrayEach'; +import arrayMap from 'lodash-es/_arrayMap'; import isArray from 'lodash-es/isArray'; import noop from 'lodash-es/noop'; -import property from 'lodash-es/internal/baseProperty'; +import property from 'lodash-es/_baseProperty'; import onlyOnce from './onlyOnce'; import setImmediate from './setImmediate'; diff --git a/build/es/priorityQueue.js b/build/es/priorityQueue.js index 9f9d3a0d0..b22e96f4b 100644 --- a/build/es/priorityQueue.js +++ b/build/es/priorityQueue.js @@ -1,6 +1,6 @@ 'use strict'; -import arrayEach from 'lodash-es/internal/arrayEach'; +import arrayEach from 'lodash-es/_arrayEach'; import isArray from 'lodash-es/isArray'; import noop from 'lodash-es/noop'; diff --git a/build/es/sortBy.js b/build/es/sortBy.js index b4c8b8ee4..75d61ca3c 100644 --- a/build/es/sortBy.js +++ b/build/es/sortBy.js @@ -1,7 +1,7 @@ 'use strict'; -import arrayMap from 'lodash-es/internal/arrayMap'; -import property from 'lodash-es/internal/baseProperty'; +import arrayMap from 'lodash-es/_arrayMap'; +import property from 'lodash-es/_baseProperty'; import map from './map'; diff --git a/build/es/times.js b/build/es/times.js index da2b31ff6..a03cd0c0c 100644 --- a/build/es/times.js +++ b/build/es/times.js @@ -1,7 +1,7 @@ 'use strict'; import map from './map'; -import range from 'lodash-es/internal/baseRange'; +import range from 'lodash-es/_baseRange'; export default function (count, iterator, callback) { map(range(0, count, 1), iterator, callback); diff --git a/build/es/timesLimit.js b/build/es/timesLimit.js index 9c2fecac1..391652fc8 100644 --- a/build/es/timesLimit.js +++ b/build/es/timesLimit.js @@ -1,7 +1,7 @@ 'use strict'; import mapLimit from './mapLimit'; -import range from 'lodash-es/internal/baseRange'; +import range from 'lodash-es/_baseRange'; export default function timeLimit(count, limit, iterator, cb) { return mapLimit(range(0, count, 1), limit, iterator, cb); diff --git a/build/es/timesSeries.js b/build/es/timesSeries.js index ebcb34504..f73a43520 100644 --- a/build/es/timesSeries.js +++ b/build/es/timesSeries.js @@ -1,7 +1,7 @@ 'use strict'; import mapSeries from './mapSeries'; -import range from 'lodash-es/internal/baseRange'; +import range from 'lodash-es/_baseRange'; export default function (count, iterator, callback) { mapSeries(range(0, count, 1), iterator, callback); diff --git a/build/internal/consoleFunc.js b/build/internal/consoleFunc.js index de591e145..f7befa8ca 100644 --- a/build/internal/consoleFunc.js +++ b/build/internal/consoleFunc.js @@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = consoleFunc; -var _arrayEach = require('lodash/internal/arrayEach'); +var _arrayEach = require('lodash/_arrayEach'); var _arrayEach2 = _interopRequireDefault(_arrayEach); diff --git a/build/internal/filter.js b/build/internal/filter.js index 31ea40f76..df40b92d4 100644 --- a/build/internal/filter.js +++ b/build/internal/filter.js @@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = _filter; -var _arrayMap = require('lodash/internal/arrayMap'); +var _arrayMap = require('lodash/_arrayMap'); var _arrayMap2 = _interopRequireDefault(_arrayMap); -var _baseProperty = require('lodash/internal/baseProperty'); +var _baseProperty = require('lodash/_baseProperty'); var _baseProperty2 = _interopRequireDefault(_baseProperty); diff --git a/build/internal/queue.js b/build/internal/queue.js index 0c5c51bfa..72fc68591 100644 --- a/build/internal/queue.js +++ b/build/internal/queue.js @@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = queue; -var _arrayEach = require('lodash/internal/arrayEach'); +var _arrayEach = require('lodash/_arrayEach'); var _arrayEach2 = _interopRequireDefault(_arrayEach); -var _arrayMap = require('lodash/internal/arrayMap'); +var _arrayMap = require('lodash/_arrayMap'); var _arrayMap2 = _interopRequireDefault(_arrayMap); @@ -21,7 +21,7 @@ var _noop = require('lodash/noop'); var _noop2 = _interopRequireDefault(_noop); -var _baseProperty = require('lodash/internal/baseProperty'); +var _baseProperty = require('lodash/_baseProperty'); var _baseProperty2 = _interopRequireDefault(_baseProperty); diff --git a/build/package.json b/build/package.json index 2e0b63b28..55a457e28 100644 --- a/build/package.json +++ b/build/package.json @@ -19,8 +19,8 @@ "utility" ], "dependencies": { - "lodash": "^4.0.0", - "lodash-es": "^4.0.0" + "lodash": "^4.3.0", + "lodash-es": "^4.3.0" }, "devDependencies": { "babel-cli": "^6.3.17", @@ -71,9 +71,9 @@ }, "license": "MIT", "jam": { - "main": "async.js", + "main": "index.js", "include": [ - "async.js", + "lib/async.js", "README.md", "LICENSE" ], @@ -82,10 +82,10 @@ ] }, "spm": { - "main": "async.js" + "main": "index.js" }, "volo": { - "main": "async.js", + "main": "index.js", "ignore": [ "**/.*", "node_modules", diff --git a/build/priorityQueue.js b/build/priorityQueue.js index c42751dde..8f02f1669 100644 --- a/build/priorityQueue.js +++ b/build/priorityQueue.js @@ -67,7 +67,7 @@ exports.default = function (worker, concurrency) { return q; }; -var _arrayEach = require('lodash/internal/arrayEach'); +var _arrayEach = require('lodash/_arrayEach'); var _arrayEach2 = _interopRequireDefault(_arrayEach); diff --git a/build/sortBy.js b/build/sortBy.js index f6591a2db..0dd935f5a 100644 --- a/build/sortBy.js +++ b/build/sortBy.js @@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = sortBy; -var _arrayMap = require('lodash/internal/arrayMap'); +var _arrayMap = require('lodash/_arrayMap'); var _arrayMap2 = _interopRequireDefault(_arrayMap); -var _baseProperty = require('lodash/internal/baseProperty'); +var _baseProperty = require('lodash/_baseProperty'); var _baseProperty2 = _interopRequireDefault(_baseProperty); diff --git a/build/times.js b/build/times.js index 25aef5439..e8a81a57f 100644 --- a/build/times.js +++ b/build/times.js @@ -12,7 +12,7 @@ var _map = require('./map'); var _map2 = _interopRequireDefault(_map); -var _baseRange = require('lodash/internal/baseRange'); +var _baseRange = require('lodash/_baseRange'); var _baseRange2 = _interopRequireDefault(_baseRange); diff --git a/build/timesLimit.js b/build/timesLimit.js index 236b12379..96f52fee4 100644 --- a/build/timesLimit.js +++ b/build/timesLimit.js @@ -9,7 +9,7 @@ var _mapLimit = require('./mapLimit'); var _mapLimit2 = _interopRequireDefault(_mapLimit); -var _baseRange = require('lodash/internal/baseRange'); +var _baseRange = require('lodash/_baseRange'); var _baseRange2 = _interopRequireDefault(_baseRange); diff --git a/build/timesSeries.js b/build/timesSeries.js index 8681d9fc2..bf3042c8a 100644 --- a/build/timesSeries.js +++ b/build/timesSeries.js @@ -12,7 +12,7 @@ var _mapSeries = require('./mapSeries'); var _mapSeries2 = _interopRequireDefault(_mapSeries); -var _baseRange = require('lodash/internal/baseRange'); +var _baseRange = require('lodash/_baseRange'); var _baseRange2 = _interopRequireDefault(_baseRange); diff --git a/index.js b/index.js index 0d0b270df..031f69019 100644 --- a/index.js +++ b/index.js @@ -1 +1,3 @@ -module.exports = require("./build/") +// This is not the main file in the npm package, but here so we can use github +// tarballs as packages when necessary. +module.exports = require("./build/"); diff --git a/lib/auto.js b/lib/auto.js index 2b3db6e69..34678962e 100644 --- a/lib/auto.js +++ b/lib/auto.js @@ -1,8 +1,8 @@ 'use strict'; -import arrayEach from 'lodash/internal/arrayEach'; -import arrayEvery from 'lodash/internal/arrayEvery'; -import baseHas from 'lodash/internal/baseHas'; +import arrayEach from 'lodash/_arrayEach'; +import arrayEvery from 'lodash/_arrayEvery'; +import baseHas from 'lodash/_baseHas'; import forOwn from 'lodash/forOwn'; import indexOf from 'lodash/indexOf'; import isArray from 'lodash/isArray'; diff --git a/lib/internal/consoleFunc.js b/lib/internal/consoleFunc.js index 1ff702b95..fd8130dba 100644 --- a/lib/internal/consoleFunc.js +++ b/lib/internal/consoleFunc.js @@ -1,6 +1,6 @@ 'use strict'; -import arrayEach from 'lodash/internal/arrayEach'; +import arrayEach from 'lodash/_arrayEach'; import rest from 'lodash/rest'; export default function consoleFunc(name) { diff --git a/lib/internal/filter.js b/lib/internal/filter.js index 9f2ba8717..4d5ceb8e1 100644 --- a/lib/internal/filter.js +++ b/lib/internal/filter.js @@ -1,7 +1,7 @@ 'use strict'; -import arrayMap from 'lodash/internal/arrayMap'; -import property from 'lodash/internal/baseProperty'; +import arrayMap from 'lodash/_arrayMap'; +import property from 'lodash/_baseProperty'; export default function _filter(eachfn, arr, iterator, callback) { var results = []; diff --git a/lib/internal/queue.js b/lib/internal/queue.js index f6e665bea..87c99f87f 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -1,10 +1,10 @@ 'use strict'; -import arrayEach from 'lodash/internal/arrayEach'; -import arrayMap from 'lodash/internal/arrayMap'; +import arrayEach from 'lodash/_arrayEach'; +import arrayMap from 'lodash/_arrayMap'; import isArray from 'lodash/isArray'; import noop from 'lodash/noop'; -import property from 'lodash/internal/baseProperty'; +import property from 'lodash/_baseProperty'; import onlyOnce from './onlyOnce'; import setImmediate from './setImmediate'; diff --git a/lib/priorityQueue.js b/lib/priorityQueue.js index 6599c3eba..6cc10edbf 100644 --- a/lib/priorityQueue.js +++ b/lib/priorityQueue.js @@ -1,6 +1,6 @@ 'use strict'; -import arrayEach from 'lodash/internal/arrayEach'; +import arrayEach from 'lodash/_arrayEach'; import isArray from 'lodash/isArray'; import noop from 'lodash/noop'; diff --git a/lib/sortBy.js b/lib/sortBy.js index 8507c8940..4f1482318 100644 --- a/lib/sortBy.js +++ b/lib/sortBy.js @@ -1,7 +1,7 @@ 'use strict'; -import arrayMap from 'lodash/internal/arrayMap'; -import property from 'lodash/internal/baseProperty'; +import arrayMap from 'lodash/_arrayMap'; +import property from 'lodash/_baseProperty'; import map from './map'; diff --git a/lib/times.js b/lib/times.js index 493d3c177..72e844c88 100644 --- a/lib/times.js +++ b/lib/times.js @@ -1,7 +1,7 @@ 'use strict'; import map from './map'; -import range from 'lodash/internal/baseRange'; +import range from 'lodash/_baseRange'; export default function (count, iterator, callback) { map(range(0, count, 1), iterator, callback); diff --git a/lib/timesLimit.js b/lib/timesLimit.js index 2f3559e2e..1ea73132e 100644 --- a/lib/timesLimit.js +++ b/lib/timesLimit.js @@ -1,7 +1,7 @@ 'use strict'; import mapLimit from './mapLimit'; -import range from 'lodash/internal/baseRange'; +import range from 'lodash/_baseRange'; export default function timeLimit(count, limit, iterator, cb) { return mapLimit(range(0, count, 1), limit, iterator, cb); diff --git a/lib/timesSeries.js b/lib/timesSeries.js index 4377acb21..792727066 100644 --- a/lib/timesSeries.js +++ b/lib/timesSeries.js @@ -1,7 +1,7 @@ 'use strict'; import mapSeries from './mapSeries'; -import range from 'lodash/internal/baseRange'; +import range from 'lodash/_baseRange'; export default function (count, iterator, callback) { mapSeries(range(0, count, 1), iterator, callback); diff --git a/package.json b/package.json index 756ad2b7f..e0b56c51f 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "utility" ], "dependencies": { - "lodash": "^4.0.0", - "lodash-es": "^4.0.0" + "lodash": "^4.3.0", + "lodash-es": "^4.3.0" }, "devDependencies": { "babel-cli": "^6.3.17", From 8423f0bec47e0f6ff3652954b5ccb303fc72aeb8 Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Wed, 10 Feb 2016 16:00:17 -0800 Subject: [PATCH 22/36] use tweaked version of xyz for our publish process --- Makefile | 6 +- package.json | 3 +- support/xyz.sh | 171 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 6 deletions(-) create mode 100755 support/xyz.sh diff --git a/Makefile b/Makefile index ca9fe841b..df798bd0e 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ PACKAGE = asyncjs REQUIRE_NAME = async BABEL_NODE = babel-node UGLIFY = uglifyjs -XYZ = xyz --repo git@github.com:caolan/async.git +XYZ = support/xyz.sh --repo git@github.com:caolan/async.git BUILDDIR = build DIST = dist @@ -23,7 +23,7 @@ CJS_BUNDLE = $(BUILDDIR)/index.js ES_MODULES = $(patsubst lib/%.js, build/es/%.js, $(JS_SRC)) -all: lint test clean build +all: clean lint build test test: npm test @@ -94,8 +94,6 @@ build: clean build-bundle build-dist build-es build-config test-build .PHONY: release-major release-minor release-patch release-major release-minor release-patch: all - $(SCRIPTS)/sync-package-managers.js - git add --force *.json git add --force $(BUILDDIR) git commit -am "update minified build"; true $(XYZ) --increment $(@:release-%=%) diff --git a/package.json b/package.json index e0b56c51f..0242e49a0 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "uglify-js": "~2.4.0", "vinyl-buffer": "~1.0.0", "vinyl-source-stream": "~1.1.0", - "xyz": "^0.5.0", "yargs": "~3.9.1" }, "scripts": { @@ -94,4 +93,4 @@ "tests" ] } -} \ No newline at end of file +} diff --git a/support/xyz.sh b/support/xyz.sh new file mode 100755 index 000000000..fe3f2ece7 --- /dev/null +++ b/support/xyz.sh @@ -0,0 +1,171 @@ +#!/usr/bin/env bash + +# Slightly modified version of xyz that publishes from the build directory, +# rather than the root. + +set -e + +usage=" +Usage: xyz [options] + +Publish a new version of the npm package in the current working directory. +This involves updating the version number in package.json, committing this +change (along with any staged changes), tagging the commit, pushing to the +remote git repository, and finally publishing to the public npm registry. + +If present, component.json is updated along with package.json. + +Options: + +-b --branch + Specify the branch from which new versions must be published. + xyz aborts if run from any other branch to prevent accidental + publication of feature branches. 'master' is assumed if this + option is omitted. + +-i --increment + Specify the level of the current version number to increment. + Valid levels: 'major', 'minor', 'patch', 'premajor', 'preminor', + 'prepatch', and 'prerelease'. 'patch' is assumed if this option + is omitted. + +-m --message