Shouldn't await only be able to be used inside async functions

I’m new to JS and been playing around with the scripting block, quite alot.

I’ve been wondering about the use of the await keyword.
I think i learned somewhere that await can only be used to consume promises inside async functions.
Await is used in the main code.

Is it me who is wrong or is the script block one big async function?

It’s a good guestion and probably best answered by the Airtable engineers. I think it’s reasonable to think of a script block as function - you run it, it has a terminus, but it doesn’t resolve to a value unlike actual functions can. But it’s important to note that there’s no requirement for a function to return a value.

Since almost every facet of javascript itself are made up of functions and since javascript supports nested functions (functions within functions), I don’t think it’s necessarily an inaccurate way to think about script blocks as simple functions.

But, I tend to think of script blocks as apps and await is simply an element of the app (and functions) that allow us to apply blocking rules in a non-blocking script environment.

Ideally, script blocks should be able to return values themselves; this would be a requirement if we convince Airtable that Script Blocks are indeed the most ideal building block framework for an extensible formula framework. While the code editor suggests that a script block does not support return(), I beg to differ - this code runs fine which suggests Airtable may indeed be prepared to make it possible for script blocks to act as both little apps and functions in and of themselves.

image

More here - Guidance on "top-level" `return` in scripting blocks

3 Likes

Thank you Bill.
It was not me that got it completely wrong then :wink:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.