I received a question about async.parallel after class that I wanted to address- Sorry we ran short on time!
Q: Why wouldn’t you just call the methods in the for loop right then versus moving them into async?
A: Usually you’ll want to do something after all these async requests have completed - Such as calling a callback to let something else know your operation has completed, or maybe working with the data once you’ve got it all in one place. If you weren’t using async, you’d have to manage a counter that is being called every time an async function completes to know whether the number of times something has completed is equal to the number of calls you made. It’s a bit of a hassle.
Plus, you’ll frequently want to do something with all of the data you’ve just brought into your application as a single entity- such as if we were querying for a user’s profile information, their friends, and their interests to then store that in your database, it’d be nice if you just had to make those 3 requests and then have the results returned in one central location once they’re all completed.
So, Async’s purpose in general is that it makes working with asynchronous flows a lot easier- you can do everything async is doing by hand, but you’ll end up writing a lot more code and having to handle a bunch of cases which aren’t an issue when using the Async lib. Your code will look cleaner / be easier to read rather than nested callbacks, and you can do complex patterns like knowing when all async operations have completed easily.
Hope this helps, I had an awesome time working with you guys! Thanks for having me!
@kevinmstephens Awesome! Once you get the hang of the async library (specifically, wrapping your methods to accept a callback function) it’s really hard to go back.
Async, Lodash (a faster drop-in replacement for Underscore, plus some additional methods like deep merge! http://lodash.com/docs), and Sugar (Epic library for working with Dates, plus some other awesome additions to most native datatypes http://sugarjs.com/) are all pretty much auto-installs for all of my Node project these days.