#stop double execution of code when the time limit exceedes

2 messages · Page 1 of 1 (latest)

molten jolt
#
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

#

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