-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement <name> and <name>Series with <name>Limit #847
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
'use strict'; | ||
|
||
import eachOf from './eachOf'; | ||
import withoutIndex from './internal/withoutIndex'; | ||
import eachLimit from './eachLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default function each(arr, iterator, cb) { | ||
return eachOf(arr, withoutIndex(iterator), cb); | ||
} | ||
export default doLimit(eachLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,6 @@ | ||
'use strict'; | ||
|
||
import once from 'lodash/once'; | ||
import noop from 'lodash/noop'; | ||
import eachOfLimit from './eachOfLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
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); | ||
} | ||
} | ||
} | ||
export default doLimit(eachOfLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,6 @@ | ||
'use strict'; | ||
|
||
import once from 'lodash/once'; | ||
import noop from 'lodash/noop'; | ||
import eachOfLimit from './eachOfLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
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(); | ||
} | ||
export default doLimit(eachOfLimit, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
'use strict'; | ||
|
||
import eachOfSeries from './eachOfSeries'; | ||
import withoutIndex from './internal/withoutIndex'; | ||
import eachLimit from './eachLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default function eachSeries(arr, iterator, cb) { | ||
return eachOfSeries(arr, withoutIndex(iterator), cb); | ||
} | ||
export default doLimit(eachLimit, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
'use strict'; | ||
|
||
import createTester from './internal/createTester'; | ||
import eachOf from './eachOf'; | ||
import notId from './internal/notId'; | ||
import everyLimit from './everyLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default createTester(eachOf, notId, notId); | ||
export default doLimit(everyLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
import filter from './internal/filter'; | ||
import doParallel from './internal/doParallel'; | ||
import filterLimit from './filterLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default doParallel(filter); | ||
export default doLimit(filterLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
import filter from './internal/filter'; | ||
import doSeries from './internal/doSeries'; | ||
import filterLimit from './filterLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default doSeries(filter); | ||
export default doLimit(filterLimit, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
export default function doLimit(fn, limit) { | ||
return function (iterable, iterator, callback) { | ||
return fn(iterable, limit, iterator, callback); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
import doParallel from './internal/doParallel'; | ||
import map from './internal/map'; | ||
import mapLimit from './mapLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default doParallel(map); | ||
export default doLimit(mapLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
import map from './internal/map'; | ||
import doSeries from './internal/doSeries'; | ||
import mapLimit from './mapLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default doSeries(map); | ||
export default doLimit(mapLimit, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
'use strict'; | ||
|
||
import _parallel from './internal/parallel'; | ||
import eachOf from './eachOf'; | ||
import parallelLimit from './parallelLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default function parallel(tasks, cb) { | ||
return _parallel(eachOf, tasks, cb); | ||
} | ||
export default doLimit(parallelLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
import reject from './internal/reject'; | ||
import doParallel from './internal/doParallel'; | ||
import rejectLimit from './rejectLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default doParallel(reject); | ||
export default doLimit(rejectLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
import reject from './internal/reject'; | ||
import doSeries from './internal/doSeries'; | ||
import rejectLimit from './rejectLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default doSeries(reject); | ||
export default doLimit(rejectLimit, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
'use strict'; | ||
|
||
import identity from 'lodash/identity'; | ||
import someLimit from './someLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
import createTester from './internal/createTester'; | ||
import eachOf from './eachOf'; | ||
|
||
export default createTester(eachOf, Boolean, identity); | ||
export default doLimit(someLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
'use strict'; | ||
|
||
import map from './map'; | ||
import range from 'lodash/_baseRange'; | ||
import timesLimit from './timesLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default function (count, iterator, callback) { | ||
map(range(0, count, 1), iterator, callback); | ||
} | ||
export default doLimit(timesLimit, Infinity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
'use strict'; | ||
|
||
import mapSeries from './mapSeries'; | ||
import range from 'lodash/_baseRange'; | ||
import timesLimit from './timesLimit'; | ||
import doLimit from './internal/doLimit'; | ||
|
||
export default function (count, iterator, callback) { | ||
mapSeries(range(0, count, 1), iterator, callback); | ||
} | ||
export default doLimit(timesLimit, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the point of these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test fail without them. With how eachOfLimit is executed since the first iteration is synchronous, it executed the second iteration and so on so this causes multiple calls to
test.done()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, alright that's breaking and should be fixed in v2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a 2.x branch we could merge this PR into. Although, I'm a bit hesitant because it could set us up for merge hell if we end up making lots of changes on master.