dimanche 14 mars 2021

Why do I not get new random values? [closed]

I wrote a function in javascript. It should trigger all 10 secs and produce new random values, but actually the values stay the same and I don't know why.

Here is a minimal example:

async function rand1(){//... return random number};
async function rand2(){//... return random string from a given list};

async function values(){
   x = await Promise.resolve(rand1());
   y = await Promise.resolve(rand1());
   return [x.toString(), y];
}

setTimeout(() => {
  values();
}, 10000); // triggers all 10 secs

This way, the result of values() always stays the same. Does setTimeout() work for async functions? What else could I do here?

EDIT: I'm not sure, whether it's important or not: The original code connects with a postgres database via node postgres. It collects some data from there, picks random values and creates new posts out of it.




Aucun commentaire:

Enregistrer un commentaire