const logThenDelay = milliseconds => total => {
log(`${total / 1000.0} seconds!`);
return delay(milliseconds)
.then(() => total + milliseconds);
};
logThenDelay(500)(0) // logs 0 seconds!
.then(logThenDelay(500)) // after 0.5 seconds, logs 0.5 seconds!
.then(logThenDelay(500)) // after 1 second, logs 1 seconds!
.then(logThenDelay(500)); // after 1.5 seconds, logs 1.5 seconds!
let p = delay(500);
p.then(() => log('1st then!')); // after 0.5 seconds, logs 1st then!
p.then(() => log('2nd then!')); // after 0.5 seconds, logs 2nd then!
p.then(() => log('3rd then!')); // after 0.5 seconds, logs 3rd then!
p = p.then(() => Nancy.reject());
p.catch(() => log('1st catch!')); // after 0.5 seconds, logs 1st catch!
p.catch(() => log('2nd catch!')); // after 0.5 seconds, logs 2nd catch!
p.catch(() => log('3rd catch!')); // after 0.5 seconds, logs 3rd catch!