stop double execution of code when the time limit exceedes

var worker_default = {
async fetch(request, env, ctx) {
let counter = 0
while(true){
console.log(counter)
counter+=1
await new Promise((resolve) => setTimeout(resolve, 1000));
}
return new Response("Hello World!");
}
};
var worker_default = {
async fetch(request, env, ctx) {
let counter = 0
while(true){
console.log(counter)
counter+=1
await new Promise((resolve) => setTimeout(resolve, 1000));
}
return new Response("Hello World!");
}
};
Its printing 0,1,2,3...59 then again the loop is running and printing 0,1,2,3....59 then it stops
1 Reply
Mrinank
MrinankOP6mo ago
I am facing similar problem in my workers cron job where I am fetching some urls from a list in a loop and putting it in KV, but the whole schedule is running once again from middle and not finishing a very long running task completely I don't want it to run twice. If time limit exceedes then it should stop there only
Want results from more Discord servers?
Add your server