-
Notifications
You must be signed in to change notification settings - Fork 792
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
possible to yield Map object? #299
Comments
Hi, Workaround would be: yield Array.from(map.values()) \C
|
Or |
Update: This solution has some unnecessary overhead. Please have a look at @DeShadow comment. It works perfectly fine with For Example:
Where task() returns a promise and looks like: or even more simpler thus |
@harshitgupta Your code is a bit overhead. const task = x => co(function*(){
const a = yield someTask(x);
const b = yield someTask(y);
return b;
});
const result = yield array.map(x => task(x))
// or simpler const result = yield array.map(task) But
|
Awesome!!! Thanks a lot for pointing it out. I didn't know that. I am little bit confused about the error handling. I have
It doesn't seem right. :/ How would you handle it? Thanks again. |
@harshitgupta If you use
If you use
But if you don't want to catch errors in function:
|
OP is about Map (the type), not +1, Map is even more appropriate than object for this. In fact, "array or object" should really just be "iterable", as in, yielding an iterable for parallel execution. I actually think this is a pretty big deal : co should be symmetrical with the newer builtin APIs and syntaxes like Map and Set (and weak variants), as well as Objects are not actually iterables, though:
Dropping support for yielding objects would be a big breaking change, but it's not a big deal to say "iterables and plain objects". I would however suggest that non-iterable objects with a prototype other than Object or null should not be supported at all (not sure if that's the case now or not) |
Hi
I got this error, when yield a Map object,
'You may only yield a function, promise, generator, array, or object, but the following object was passed: "[object Map]"'
Is that possible to support Map?
Thanks
The text was updated successfully, but these errors were encountered: