Help

Re: I need a DELAY method & setTimeout() is undefined (not found Window)

7838 3
cancel
Showing results for 
Search instead for 
Did you mean: 
David_Koontz
6 - Interface Innovator
6 - Interface Innovator

Hey,

I’m a newbie with JavaScript so this might be obvious …

I need a delay(ms) method to slow down the script after 5 API calls (limit 5/min.). Problem is all the JavaScript help on the intertube points to the setTimeout() method of the Window object. But it appears that Window is not instantiated inside the Airtable code block, therefore, no setTimeout() method. What’s a good workaround for this?

What might I be missing - other methods?

Thanks
David

55 Replies 55

I was also using only block-native features and no external calls.

Have you been submitting more than 5 calls per second to createRecordsAsync(), updateRecordsAsync() or deleteRecordsAsync()? That’s how I ran up against what I believe to be an unpublished rate limit. In my script, I didn’t need to await the return values so I was running them in parallel instead of in series.

openside
10 - Mercury
10 - Mercury

Remove window. :slightly_smiling_face: should just be calling setTimeout() like in my code example

David_Koontz
6 - Interface Innovator
6 - Interface Innovator

Thanks @Justin_Barrett - again, the restriction is on the API I am calling Alpha Vantage.

I’ve got code that is working this morning. From @Bill.French

function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

await timeout(1000); // 1 sec pause

But I swear I had the same code last night and it did NOT work… so I’m stumped as to what magic dust makes it work today. Even with the IDE given the error codes about setTimeout().

I’m using a mix of create and update operations, though in my case I need to use await on all of them because I’m linking between various records as they’re created, so they probably aren’t triggering in quick succession.

I doubt that you could run more than 5 requests per second when using await. I didn’t see the problem until I started to run the requests in parallel. I consistently got the generic “Something went wrong” error. Then I slowed down my script to just over 5 requests per second with no other changes and the problem disappeared. I’d be curious to see if anyone else can replicate the issue.

That’s exact same code I shared with you originally :winking_face:

And where I found it as well. But there is an issue here given the subtle indicator from the editor that this is not supported. And I wonder if this morning’s API issues align with @David_Koontz failure experiences.

Do you think that the wavy red underlines in the editor means that setTimeout() is not supported? I get those wavy red underlines all the time for things that clearly are supported, so I tend to ignore the wavy red underlines after a while. Or is there something else?

For me, setTimeout() works as expected. It waits the specified amount of time and then runs the provided function with the provided parameters.

setTimeout(echoText, 1000);
setTimeout(echoText, 2000, "Hello, World, again!");
await input.textAsync("Just something to keep the script from ending");
function echoText(myText = "Hello, World!") {
    output.text(myText);
}

That’s exactly what it is suggesting.

The **red underline** has been a tradition in IDE for 20 years… it has various meanings… but general a reason for the developer to stop and fix it.

I wonder why the Airtable IDE (tool) is fooled??? I’m guessing it is the difference between parse time and run time - the setTimeout() method must be found at runtime for it to work… but at code parse (interpretation) time - it’s an error.

One of my JS experts mentioned this aspect this morning.