Next.js singletons and dev mode
Unanswered
Mugger Crocodile posted this in #help-forum
Mugger CrocodileOP
Hi, how can one create a a (server-side) singleton object in dev mode? The code suggested here in this article by Vercel themselves doesn't work (for me at least): https://vercel.com/guides/nextjs-prisma-postgres#step-4.-install-and-generate-prisma-client
The actual reason that we want this is to make sure that we can run a single worker thread and make sure there's only one running. Running multiple threads could cause serious problems. A singleton would do the trick. But in dev mode code is continuously re-evaluated and any global vars reset.
The actual reason that we want this is to make sure that we can run a single worker thread and make sure there's only one running. Running multiple threads could cause serious problems. A singleton would do the trick. But in dev mode code is continuously re-evaluated and any global vars reset.
1 Reply
Silver Fox
Have you found a solution for this?