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¤cy_to=eth')
.then(response => response.json())
.then(json => console.log(json));
}, 3);