/** Возвращает случайное целочисленное число*/
const randomInt = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/** Для ожидания */
const delay = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
}
let counter = 0;
/** Рекурсивный промис */
const test = () => {
return new Promise( resolve => {
let random = randomInt(300, 1800);
delay(random).then(() => {
counter++;
console.log("Counter:", counter, "Random:", random);
resolve(test());
})
})
}
test()