I know the sleep(t) function exists, but only exists in seconds. Can we use default javascript functions such as setTimeout if I wanted to wait for approx 400ms (in this case between two api calls being made in the default function.
I know those aren’t technically “sleeps” but is there any reliable way to “wait” for a time in milliseconds?
edit: It looks like timers does exist and appears to work. Right now my code looks like this (i’ve made it more basic looking for clarity):
So it does appear to wait around 400ms. However I am curious on one thing. Since setTimeout is an async function, does the default function itself wait for the timeout to end before “ending” that VU’s execution.
IE for a VU that runs this thread does it work like this:
Start Default Function
Do first HTTP Request (against firstURL)
Wait 400ms
While it’s waiting end the default function
Some other thread finishes the HTTP request against secondURL?
or will it wait for the secondURL to finish and the setTimeout Function to finish before ending the default function?
Yeah I made a mistake with the string formatted time for setTimeout. I don’t need this to be async necessarily I just need to make it where one request happens exactly 400ms after another.
sleep is perfect for this. However according to the docs sleep only accepts seconds, so I assume I cannot do sleep(.4) for example.
I realize my code example isn’t great, but it’s the only way so far I can “sorta” replicate a 400ms sleep to then execute the 2nd request.
Oh thats even better. And yeah good point I should’ve just tried it (but it’s hard to test exactly so I wanted to confirm that it actually "could’ work like that by asking here)