Waiting For Multiple Actions
In a web app I needed to wait for a generated user ID from the server and also for the user to enter a name. Promises came in handy, here's one way of waiting for multiple actions to finish.
Demo: Press start to get info about the files:
Size of all files: (press Start)
The info gets displayed only after all files have been fetched.
Here's the code (pulled directly from the source of this page), the main feature is the Promise.all function (also see all comments).
Promise.all waits for the promises then passes the values as an array.
Be sure to always catch().
If you use .blob() in a real project, make sure to feature-detect it.
If you enjoyed this post, follow me on Twitter