Skip to content

Glad.intermission

Charlie Mitchell edited this page Mar 21, 2018 · 1 revision

intermission

Added in 1.1.4

Glad.intermission is a great way to space out operations (asynchronous). For example, let's say that you want to make an external API call for every model that a query returned, but the API specifies that you should only make 1 request per second to it. You can use Glad.itermission to accomplish this.

  Model.find(...).then(async records => {

    let i = 0;
    let count = records.length;

    for (i; i < count; i +=1) {
      await someApi.lookupAndDoStuff(records[i].id);
      await Glad.intermission(1000);
    }

  })

The above will wait 1 second between each iteration of the for loop.

Clone this wiki locally