I am working on an application that needs to perform a bunch of HTTP requests, but the problem is that i can not fire them all at once or immediately one after the other. Doing so will get my IP address blocked, which i obviously want to avoid, so i need to introduce some delay between each HTTP request.

By putting all the requests in a promise chain i can fire them in sequence, but i am left with the problem of introducing some delay between each request.

I created a very simple node module for introducing a Promise Based Delay in my chain:

var delay = require('promise-temporal-delay');

// Promise Chain
request1().then(function(response){

    // Do something with the response

    // Wait for 2 seconds
    return delay(2000);

}).then(function() {

    return request2();

}).then(function(response) {

    // Do something with the response

    // Wait for another 2 seconds
    return delay(2000);

}).then(function() {

   return request3();

}).then(function(response) {

   // Do something with the response

   // Finish the promise chain

});