NuxtN
Nuxt2y ago
19 replies
Yaiko

Nitro plugin while loop stucks server

I have a simple plugin that reads a file and runs some code periodically.

const task = () => {
  while (1){
    // Reads file and runs code if data on it
  }
}

export default defineNitroPlugin(() => {
  task();
});

The while makes the server go stuck, is there an alternative to run a code like that in the server background without breaking the rest of the server?
Thanks.

https://github.com/nuxt/nuxt/issues/26809
GitHub
Environment Operating System: Darwin Node Version: v18.15.0 Nuxt Version: 3.11.2 CLI Version: 3.11.1 Nitro Version: 2.9.6 Package Manager: bun@1.1.3 Builder: - User Config: devtools, app, runtimeCo...
Was this page helpful?