function repeat callback seconds let fn repeat callback seconds let pr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
function repeat(callback, seconds) {
let fn = () => repeat(callback, seconds);
let promise = Promise.resolve(callback());
promise
.catch(err => console.error(err))
.then(() => setTimeout(fn, seconds * 1000));
}
repeat(function () {
console.log('example, every 1 seconds');
}, 1)
repeat(function () {
// example with request
return fetch('https://api.simpleswap.io/get_min?currency_from=btc&currency_to=eth')
.then(response => response.json())
.then(json => console.log(json));
}, 3);