@@ -95,7 +95,7 @@ function applyEach$1(eachfn) {
9595 var go = initialParams ( function ( args , callback ) {
9696 var that = this ;
9797 return eachfn ( fns , function ( fn , cb ) {
98- fn . apply ( that , args . concat ( [ cb ] ) ) ;
98+ fn . apply ( that , args . concat ( cb ) ) ;
9999 } , callback ) ;
100100 } ) ;
101101 if ( args . length ) {
@@ -200,8 +200,7 @@ function baseGetTag(value) {
200200 if ( value == null ) {
201201 return value === undefined ? undefinedTag : nullTag ;
202202 }
203- value = Object ( value ) ;
204- return ( symToStringTag && symToStringTag in value )
203+ return ( symToStringTag && symToStringTag in Object ( value ) )
205204 ? getRawTag ( value )
206205 : objectToString ( value ) ;
207206}
@@ -332,6 +331,10 @@ function isArrayLike(value) {
332331 return value != null && isLength ( value . length ) && ! isFunction ( value ) ;
333332}
334333
334+ // A temporary value used to identify if the loop should be broken.
335+ // See #1064, #1293
336+ var breakLoop = { } ;
337+
335338/**
336339 * This method returns `undefined`.
337340 *
@@ -636,7 +639,7 @@ var freeProcess = moduleExports$1 && freeGlobal.process;
636639/** Used to access faster Node.js helpers. */
637640var nodeUtil = ( function ( ) {
638641 try {
639- return freeProcess && freeProcess . binding ( 'util' ) ;
642+ return freeProcess && freeProcess . binding && freeProcess . binding ( 'util' ) ;
640643 } catch ( e ) { }
641644} ( ) ) ;
642645
@@ -841,10 +844,6 @@ function onlyOnce(fn) {
841844 } ;
842845}
843846
844- // A temporary value used to identify if the loop should be broken.
845- // See #1064, #1293
846- var breakLoop = { } ;
847-
848847function _eachOfLimit ( limit ) {
849848 return function ( obj , iteratee , callback ) {
850849 callback = once ( callback || noop ) ;
@@ -929,10 +928,10 @@ function eachOfArrayLike(coll, iteratee, callback) {
929928 callback ( null ) ;
930929 }
931930
932- function iteratorCallback ( err ) {
931+ function iteratorCallback ( err , value ) {
933932 if ( err ) {
934933 callback ( err ) ;
935- } else if ( ++ completed === length ) {
934+ } else if ( ++ completed === length || value === breakLoop ) {
936935 callback ( null ) ;
937936 }
938937 }
@@ -1521,7 +1520,7 @@ var auto = function (tasks, concurrency, callback) {
15211520 var runningTasks = 0 ;
15221521 var hasError = false ;
15231522
1524- var listeners = { } ;
1523+ var listeners = Object . create ( null ) ;
15251524
15261525 var readyTasks = [ ] ;
15271526
@@ -1549,7 +1548,7 @@ var auto = function (tasks, concurrency, callback) {
15491548
15501549 arrayEach ( dependencies , function ( dependencyName ) {
15511550 if ( ! tasks [ dependencyName ] ) {
1552- throw new Error ( 'async.auto task `' + key + '` has a non-existent dependency in ' + dependencies . join ( ', ' ) ) ;
1551+ throw new Error ( 'async.auto task `' + key + '` has a non-existent dependency `' + dependencyName + '` in ' + dependencies . join ( ', ' ) ) ;
15531552 }
15541553 addListener ( dependencyName , function ( ) {
15551554 remainingDependencies -- ;
@@ -1611,7 +1610,7 @@ var auto = function (tasks, concurrency, callback) {
16111610 } ) ;
16121611 safeResults [ key ] = args ;
16131612 hasError = true ;
1614- listeners = [ ] ;
1613+ listeners = Object . create ( null ) ;
16151614
16161615 callback ( err , safeResults ) ;
16171616 } else {
@@ -1828,15 +1827,17 @@ function asciiToArray(string) {
18281827
18291828/** Used to compose unicode character classes. */
18301829var rsAstralRange = '\\ud800-\\udfff' ;
1831- var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23' ;
1832- var rsComboSymbolsRange = '\\u20d0-\\u20f0' ;
1830+ var rsComboMarksRange = '\\u0300-\\u036f' ;
1831+ var reComboHalfMarksRange = '\\ufe20-\\ufe2f' ;
1832+ var rsComboSymbolsRange = '\\u20d0-\\u20ff' ;
1833+ var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange ;
18331834var rsVarRange = '\\ufe0e\\ufe0f' ;
18341835
18351836/** Used to compose unicode capture groups. */
18361837var rsZWJ = '\\u200d' ;
18371838
18381839/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
1839- var reHasUnicode = RegExp ( '[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']' ) ;
1840+ var reHasUnicode = RegExp ( '[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']' ) ;
18401841
18411842/**
18421843 * Checks if `string` contains Unicode symbols.
@@ -1851,13 +1852,15 @@ function hasUnicode(string) {
18511852
18521853/** Used to compose unicode character classes. */
18531854var rsAstralRange$1 = '\\ud800-\\udfff' ;
1854- var rsComboMarksRange$1 = '\\u0300-\\u036f\\ufe20-\\ufe23' ;
1855- var rsComboSymbolsRange$1 = '\\u20d0-\\u20f0' ;
1855+ var rsComboMarksRange$1 = '\\u0300-\\u036f' ;
1856+ var reComboHalfMarksRange$1 = '\\ufe20-\\ufe2f' ;
1857+ var rsComboSymbolsRange$1 = '\\u20d0-\\u20ff' ;
1858+ var rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1 ;
18561859var rsVarRange$1 = '\\ufe0e\\ufe0f' ;
18571860
18581861/** Used to compose unicode capture groups. */
18591862var rsAstral = '[' + rsAstralRange$1 + ']' ;
1860- var rsCombo = '[' + rsComboMarksRange$1 + rsComboSymbolsRange $1 + ']' ;
1863+ var rsCombo = '[' + rsComboRange $1 + ']' ;
18611864var rsFitz = '\\ud83c[\\udffb-\\udfff]' ;
18621865var rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')' ;
18631866var rsNonAstral = '[^' + rsAstralRange$1 + ']' ;
@@ -2251,6 +2254,7 @@ function queue(worker, concurrency, payload) {
22512254
22522255 var workers = 0 ;
22532256 var workersList = [ ] ;
2257+ var isProcessing = false ;
22542258 var q = {
22552259 _tasks : new DLL ( ) ,
22562260 concurrency : concurrency ,
@@ -2274,6 +2278,12 @@ function queue(worker, concurrency, payload) {
22742278 _insert ( data , true , callback ) ;
22752279 } ,
22762280 process : function ( ) {
2281+ // Avoid trying to start too many processing operations. This can occur
2282+ // when callbacks resolve synchronously (#1267).
2283+ if ( isProcessing ) {
2284+ return ;
2285+ }
2286+ isProcessing = true ;
22772287 while ( ! q . paused && workers < q . concurrency && q . _tasks . length ) {
22782288 var tasks = [ ] ,
22792289 data = [ ] ;
@@ -2298,6 +2308,7 @@ function queue(worker, concurrency, payload) {
22982308 var cb = onlyOnce ( _next ( tasks ) ) ;
22992309 worker ( data , cb ) ;
23002310 }
2311+ isProcessing = false ;
23012312 } ,
23022313 length : function ( ) {
23032314 return q . _tasks . length ;
@@ -2319,12 +2330,7 @@ function queue(worker, concurrency, payload) {
23192330 return ;
23202331 }
23212332 q . paused = false ;
2322- var resumeCount = Math . min ( q . concurrency , q . _tasks . length ) ;
2323- // Need to call q.process once per concurrent
2324- // worker to preserve full concurrency after pause
2325- for ( var w = 1 ; w <= resumeCount ; w ++ ) {
2326- setImmediate$1 ( q . process ) ;
2327- }
2333+ setImmediate$1 ( q . process ) ;
23282334 }
23292335 } ;
23302336 return q ;
@@ -2535,9 +2541,9 @@ var seq$1 = rest(function seq(functions) {
25352541 }
25362542
25372543 reduce ( functions , args , function ( newargs , fn , cb ) {
2538- fn . apply ( that , newargs . concat ( [ rest ( function ( err , nextargs ) {
2544+ fn . apply ( that , newargs . concat ( rest ( function ( err , nextargs ) {
25392545 cb ( err , nextargs ) ;
2540- } ) ] ) ) ;
2546+ } ) ) ) ;
25412547 } , function ( err , results ) {
25422548 cb . apply ( that , [ err ] . concat ( results ) ) ;
25432549 } ) ;
@@ -2700,36 +2706,30 @@ var constant = rest(function (values) {
27002706 } ) ;
27012707} ) ;
27022708
2703- function _createTester ( eachfn , check , getResult ) {
2704- return function ( arr , limit , iteratee , cb ) {
2705- function done ( ) {
2706- if ( cb ) {
2707- cb ( null , getResult ( false ) ) ;
2708- }
2709- }
2710- function wrappedIteratee ( x , _ , callback ) {
2711- if ( ! cb ) return callback ( ) ;
2712- iteratee ( x , function ( err , v ) {
2713- // Check cb as another iteratee may have resolved with a
2714- // value or error since we started this iteratee
2715- if ( cb && ( err || check ( v ) ) ) {
2716- if ( err ) cb ( err ) ; else cb ( err , getResult ( true , x ) ) ;
2717- cb = iteratee = false ;
2718- callback ( err , breakLoop ) ;
2709+ function _createTester ( check , getResult ) {
2710+ return function ( eachfn , arr , iteratee , cb ) {
2711+ cb = cb || noop ;
2712+ var testPassed = false ;
2713+ var testResult ;
2714+ eachfn ( arr , function ( value , _ , callback ) {
2715+ iteratee ( value , function ( err , result ) {
2716+ if ( err ) {
2717+ callback ( err ) ;
2718+ } else if ( check ( result ) && ! testResult ) {
2719+ testPassed = true ;
2720+ testResult = getResult ( true , value ) ;
2721+ callback ( null , breakLoop ) ;
27192722 } else {
27202723 callback ( ) ;
27212724 }
27222725 } ) ;
2723- }
2724- if ( arguments . length > 3 ) {
2725- cb = cb || noop ;
2726- eachfn ( arr , limit , wrappedIteratee , done ) ;
2727- } else {
2728- cb = iteratee ;
2729- cb = cb || noop ;
2730- iteratee = limit ;
2731- eachfn ( arr , wrappedIteratee , done ) ;
2732- }
2726+ } , function ( err ) {
2727+ if ( err ) {
2728+ cb ( err ) ;
2729+ } else {
2730+ cb ( null , testPassed ? testResult : getResult ( false ) ) ;
2731+ }
2732+ } ) ;
27332733 } ;
27342734}
27352735
@@ -2772,7 +2772,7 @@ function _findGetResult(v, x) {
27722772 * // result now equals the first file in the list that exists
27732773 * });
27742774 */
2775- var detect = _createTester ( eachOf , identity , _findGetResult ) ;
2775+ var detect = doParallel ( _createTester ( identity , _findGetResult ) ) ;
27762776
27772777/**
27782778 * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a
@@ -2796,7 +2796,7 @@ var detect = _createTester(eachOf, identity, _findGetResult);
27962796 * (iteratee) or the value `undefined` if none passed. Invoked with
27972797 * (err, result).
27982798 */
2799- var detectLimit = _createTester ( eachOfLimit , identity , _findGetResult ) ;
2799+ var detectLimit = doParallelLimit ( _createTester ( identity , _findGetResult ) ) ;
28002800
28012801/**
28022802 * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time.
@@ -2818,11 +2818,11 @@ var detectLimit = _createTester(eachOfLimit, identity, _findGetResult);
28182818 * (iteratee) or the value `undefined` if none passed. Invoked with
28192819 * (err, result).
28202820 */
2821- var detectSeries = _createTester ( eachOfSeries , identity , _findGetResult ) ;
2821+ var detectSeries = doLimit ( detectLimit , 1 ) ;
28222822
28232823function consoleFunc ( name ) {
28242824 return rest ( function ( fn , args ) {
2825- fn . apply ( null , args . concat ( [ rest ( function ( err , args ) {
2825+ fn . apply ( null , args . concat ( rest ( function ( err , args ) {
28262826 if ( typeof console === 'object' ) {
28272827 if ( err ) {
28282828 if ( console . error ) {
@@ -2834,7 +2834,7 @@ function consoleFunc(name) {
28342834 } ) ;
28352835 }
28362836 }
2837- } ) ] ) ) ;
2837+ } ) ) ) ;
28382838 } ) ;
28392839}
28402840
@@ -2923,7 +2923,7 @@ function doDuring(fn, test, callback) {
29232923 * passes. The function is passed a `callback(err)`, which must be called once
29242924 * it has completed with an optional `err` argument. Invoked with (callback).
29252925 * @param {Function } test - synchronous truth test to perform after each
2926- * execution of `iteratee`. Invoked with the non-error callback results of
2926+ * execution of `iteratee`. Invoked with the non-error callback results of
29272927 * `iteratee`.
29282928 * @param {Function } [callback] - A callback which is called after the test
29292929 * function has failed and repeated execution of `iteratee` has stopped.
@@ -3220,7 +3220,7 @@ function notId(v) {
32203220 * // if result is true then every file exists
32213221 * });
32223222 */
3223- var every = _createTester ( eachOf , notId , notId ) ;
3223+ var every = doParallel ( _createTester ( notId , notId ) ) ;
32243224
32253225/**
32263226 * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time.
@@ -3242,7 +3242,7 @@ var every = _createTester(eachOf, notId, notId);
32423242 * `iteratee` functions have finished. Result will be either `true` or `false`
32433243 * depending on the values of the async tests. Invoked with (err, result).
32443244 */
3245- var everyLimit = _createTester ( eachOfLimit , notId , notId ) ;
3245+ var everyLimit = doParallelLimit ( _createTester ( notId , notId ) ) ;
32463246
32473247/**
32483248 * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time.
@@ -3620,14 +3620,14 @@ function memoize(fn, hasher) {
36203620 queues [ key ] . push ( callback ) ;
36213621 } else {
36223622 queues [ key ] = [ callback ] ;
3623- fn . apply ( null , args . concat ( [ rest ( function ( args ) {
3623+ fn . apply ( null , args . concat ( rest ( function ( args ) {
36243624 memo [ key ] = args ;
36253625 var q = queues [ key ] ;
36263626 delete queues [ key ] ;
36273627 for ( var i = 0 , l = q . length ; i < l ; i ++ ) {
36283628 q [ i ] . apply ( null , args ) ;
36293629 }
3630- } ) ] ) ) ;
3630+ } ) ) ) ;
36313631 }
36323632 } ) ;
36333633 memoized . memo = memo ;
@@ -4450,7 +4450,7 @@ var retryable = function (opts, task) {
44504450 }
44514451 return initialParams ( function ( args , callback ) {
44524452 function taskFn ( cb ) {
4453- task . apply ( null , args . concat ( [ cb ] ) ) ;
4453+ task . apply ( null , args . concat ( cb ) ) ;
44544454 }
44554455
44564456 if ( opts ) retry ( opts , taskFn , callback ) ; else retry ( taskFn , callback ) ;
@@ -4555,7 +4555,7 @@ function series(tasks, callback) {
45554555 * // if result is true then at least one of the files exists
45564556 * });
45574557 */
4558- var some = _createTester ( eachOf , Boolean , identity ) ;
4558+ var some = doParallel ( _createTester ( Boolean , identity ) ) ;
45594559
45604560/**
45614561 * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time.
@@ -4578,7 +4578,7 @@ var some = _createTester(eachOf, Boolean, identity);
45784578 * Result will be either `true` or `false` depending on the values of the async
45794579 * tests. Invoked with (err, result).
45804580 */
4581- var someLimit = _createTester ( eachOfLimit , Boolean , identity ) ;
4581+ var someLimit = doParallelLimit ( _createTester ( Boolean , identity ) ) ;
45824582
45834583/**
45844584 * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time.
0 commit comments