i am running a map/reduce script and each interva...
# suitescript
s
i am running a map/reduce script and each interval will make an external API call , there server will only take new requests that are spaced at 1-2 second interval any ideas as js doesn't have a sleep blocking method
one idea i saw online is to create my own function
Copy code
const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}
s
The problem is that there is an instruction count limit to suitescripts. It doesn’t work like a governance limit, but once too many lines of code have executed, it will halt the script. Any form of busy waiting will likely hit that limit.
It’s by no means a “good” approach, but you could load a record or file from the filing cabinet to waste some time. Basically a few I/O operations should slow the script down a lot, though the amount of time spent will be highly variable.
b
best approach is probably to find or create a webservice that responds after a predefined delay
✔️ 1
second best is to implement sleep, preferably one that uses instructions slow enough that it yields before hitting an instruction count limit
the one you have is mostly useless, suitescript does not expose setTimeout
s
Someone has a service they stood up for this for SuiteScripters here
I want to say @darrenhillconsulting?
d
That we do!
s
so this is the line of code i added
Copy code
https.get({url: "<https://httpbin.org/delay/1.6>"})
b
that is my favorite http echo service