Return a promise from the then handler, which waits:
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
If you want to "pass" the meaning of a promise, then
.then(x => new Promise(resolve => setTimeout(() => resolve(x), 1000)))
To avoid this pattern everywhere, write a utility function:
function sleeper(ms) { return function(x) { return new Promise(resolve => setTimeout(() => resolve(x), ms)); }; }
then use it as in
.then(sleeper(1000)).then(...)
user663031
source share