Synchronizing data between threads

I’m trying to synchronize multiple threads (array.each() in parallel) sending data to an API while staying within the rate limits. I’ve tried a number of ways to check a “last sent time” variable to set sleep times but they don’t seem to work. Session is the last scope I tried and I’m still not having luck. Is there a memory scope or another technique I can use to do this?

If you’re just asking what variable scopes should be available to all of the threads, I would assume request or variables would be a good place to start. I suppose session would work too, but that assumes you’re only running a single request in that session.

Does the API you’re hitting return a specific status code/response when you’ve hit your rate limit. If so, just check for that response and then have the thread sleep for a bit and try the request again.

It does return a specific status code and I am pausing, but with 5 threads running, they all hit the timeout and its just not elegant.

I tried “this” thinking that was the same as “variables” but setting values there seems to get ignored by new threads as they spawn.