-
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
Allow to use generators #579
Comments
Unless I'm misunderstanding, isn't that what visionmedia/co is about, rather than async? |
No, they are different things. Co is about flow control using generators, that's mostly an intelligent hack. What I'm talking about is to use generators in the same way that async.js use arrays for data processing in a similar way of Python itertools, where you can be able to use any iterable object (any object that implement the iterator protocol, like lists, dicts and generators). |
Support could be added pretty easily to |
A quick workaround is |
Closing this in favor of #839 -- I think supporting arbitrary ES6 iterators covers a lot of things -- Maps, Sets, Generators, etc... |
Yes, both issues are similar. |
I just realized that generators don't implement the iterator protocol, meaning we'll need separate support for them. This will prove to be tricky, since there doesn't seem to be a bulletproof way to detect generator functions. |
@jdalton any interest in adding |
Actually nevermind there's no reason for us to detect whether its a generator @aearly, if the iterable passed to |
It's really tricky, since our iterator handling checks an object for a |
Perhaps |
I'd say if item is a function, we call the function assuming it will follow On Thu, Jun 30, 2016 at 5:22 PM, Alex Early [email protected]
|
The only pitfall I can think of is when someone accidentally passes a function as the wrong arg -- you'd get an error like "undefined has no property Can't think of any use case where passing a function would be a valid use case in the future, so it might be sufficient. |
meanwhile, i am in need of async's signatures with async/await (through ES6 generator & co) supports. So, i ended up writing a dedicated project for it async-co. |
I think our current support is sufficient. You can do this today, and it works: function* gen(count) {
for (var i = 0; i < count; i++)
yield i;
}
async.map(gen(5), (val, cb) => {
cb(null, val * 2)
}, (err, res) => {
// res = [0, 2, 4, 6, 8]
}) The generator support was within us the whole time. 👸 🌠 👠 |
Allow to use EcmaScript 6 iterators and generators instead of Array objects.
The text was updated successfully, but these errors were encountered: