Apparently, Goja doesn’t support Javascript setTimeouts (nor any NodeJS functionality) and in the Nakama Javascript ambient theres no setTimeout defined, so what can I use/do instead?
I’ve tried a couple of solutions suggested by ChatGPT:
- Creating a Go function to mimic
setTimeout
and exposing it to the JavaScript environment. (impractical) - Recreating
setTimeout
in JavaScript using an event queue and a basic event loop.
Unfortunately, the second solution didn’t work, likely due to limitations within Goja.
I really need a function similar to setTimeout
to implement a rate-limiting solution with token expiry scheduling for some Socket RPC messages in Nakama. These limitations of Goja are making me skeptical about the effectiveness of using the TypeScript runtime as recommended in the official documentation .
Given these challenges, I am beginning to think that using the Go runtime might be more effective and could potentially reduce my development time. I’ve already faced difficulties patching some npm packages to be compatible, and now the lack of support for global variables in the Typescript runtime is going to complicate the ratelimit logic a bit.
Simple tasks that should be straightforward are taking up some significant development time due to these limitations. Could anyone suggest a workaround or an alternative approach? Or do you think switching to the Go runtime would be a better option for using external dependencies? Or if the additional work to make things working in the TypeScript runtime is worth it?
Thank you in advance for your help and insights