When you are writing JavaScript, callbacks are one of the most confusing concepts. Promises are the new approach to improve working with async code...
For further actions, you may consider blocking this person and/or reporting abuse
Excellent article, I only have one suggestion.
Avoid using either
.forEachor.reducefor sequential promise execution - at least when overwriting references to the promises.Either use plain function recursion, or use a lib like bluebird.
Bluebird has features builtin for exactly this situation, including
.mapSeriesand concurrent execution limits, like.map(fn, {concurrency: CPU_COUNT})Example with Bluebird:
Also, another example of bluebird features,
promisifyexisting callback-based libs using a common method.So to read a file w/ Promises, use:
Good point! I mainly wanted to explain how to handle it without the help of an additional tool in a still elegant solution. I think a recursive function wouldn't make it too readable. But yeah I agree that you should ideally use something that is a bit more sophisticated. Bluebird is certainly a good solution for this.
THANK YOU!
Glad you enjoyed it :)
Thanks for this! Great article! :)
Thank you! :)
Fantastic article, thanks! Shared around the office
Thanks a lot! :)
This is amazing! This is exactly what I needed, thank you. 😬