You should all be familiar with ES6 promises by now as a way of handling asynchronicity in a more organized way. The simplest kind of asynch that we regularily come across in JavaScript is setTimeout, which normally takes this pattern.

This is just fine, until you have more that one going on and you need to do something based on all of them having completed. This is where promises come into their own. Here’s setTimeout, but promise based.

and you can use it like this.

Doesn’t seem like a great improvement over setTimeout, until you do this.

If you’re not using promises yet, then you should have a look. Life becomes a lot simpler.
For more like this see Google Apps Scripts Snippets
Why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.