-
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
Pass key to iterator if async.each() iterator takes 3 arguments #321
Conversation
@@ -70,6 +77,12 @@ | |||
return keys; | |||
}; | |||
|
|||
var _length = function (arr) { | |||
if (arr instanceof Array) return arr.length; |
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.
instanceof Array is not reliable. you should use Array.isArray(), or Object.prototype.toString.call(arr) === '[object Array]'
What about this feature? =) |
Still waiting for updates from @olalonde :-) |
Async does not use function arity to alter behaviour, since it can be unreliable in some cases. |
@caolan when can function arity be unreliable? jQuery uses this technique, I believe. |
If you did something like There is a PR open to add a |
What @aearly said :) |
@aearly 's example will also be broken with the native ["fileA.txt", "fileB.txt"].forEach(fs.readFileSync); Cause the native will pass 0, 1 as the encodings. I mean, the example with the |
@gobwas You're right about how the native The way |
@aearly yes, exactly, it will fall in the same reason. And thats why we can |
@aearly Was reading your comment from mobile, and not catched the last sentence. I agree that this feature breaks backward compatibility. But, async now at version 0.9.0, which means, by semver, that it is still not stable. This is a technical question, how to minimize backward compatibility issues. I think the interface of native iterators could be the leading idea in this question. |
#168 addresses your concerns -- it would be backwards compatible since it introduces a new method. While async is technically 0.x which is "the wild west" as far as semver is concerned, async is still used by thousands of projects and a change like what you propose would break tons of people's apps. (Some people have argued that async is ready for 1.0, though: see #562.) |
@aearly Mostly I agree with you. But. When you will release 2.0 version of async, will it be compatible to the current version? And will tons of people's apps will be broken of it? |
I have implemented a way to optionally pass a key/index argument to the async.each iterator.
It is backwards compatible since it omits the key/index argument for iterator functions that accept less than 3 arguments.
All tests pass.
See issue #72.