I am rewriting my TypeScript projects to Golang and I encountered a problem:
I am running a for loop which starts up async workers on program load. If I understood correctly Go routines are a way to run async code concurrently. What I'd like to do is restart the function once it is done, indefinitely.
In TypeScript it looks something like
async function init() {
const count = async Users.getCount();
// run all workers concurrently
for (let i = 0; i < count; i += PER_WORKER) {
const id = i / PER_WORKER;
worker(id);
}
}
async worker(id: number) {
await new Promise((resolve) => {
// do stuff
resolve();
})
// restart function
worker(workerId);
}
in Go I have pretty similar stuff, but when re-calling the function inside it just makes a mess? I thought of running the function by interval but I cannot know in advance the time it takes...
Thank you NVH