Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Now I wonder what would be the good way to make a forEach that actually returns when all elements have been executed?


Bluebird has this built in. For a quick userscript where I needed something similar, I created this which works ( warning: no unit tests, but it works for me )

https://gist.github.com/dcherman/4dfba0d72c008ee5b59d

It's a reduce function, but it could work as a forEach as well.


Bluebird has a `Promise.each` which does this. Also, you can use `thenable chaining` - make an initial promise and then chain it on each iteration - it becomes very similar to a for loop. I can add an example if you'd like.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: