This snippet shows how to use setInterval on autocode
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//Code by Jacob Lee
async function intervalFunction() {
console.log('Hello I am an interval!');
}
//The main problem is that setInterval does not keep the function active
//This is being solved by letting it wait for a "resolve" message
//It is very similar to the sleep function in this case
await new Promise((resolve) => {
let count = 0;
setInterval(async () => {
if (count > 5) {
//resolve message after 6 executions
return resolve();
}
await intervalFunction();
count++;
}, 500);//sets the repeat time to every 500 ms (milliseconds)
});