Sie sind nicht angemeldet.

1

Dienstag, 26. September 2023, 06:28

Using async await in javascript action

Hey all
I wanna using async await in javascript action. Is it possible?

2

Freitag, 29. September 2023, 15:12

Sure, just like in any other Javascript code - the code only need to be inside a 'async' function:

Quellcode

1
2
3
4
5
6
7
8
9
10
<action ... type="js"><![CDATA[

async function asyncCall()
{
  ... inside a async function you could use await ...
}

asyncCall();

]]></action>


or just run directly an anonymous function:

Quellcode

1
2
3
4
5
6
<action ... type="js"><![CDATA[
(async function()
{
  ... inside a async function you could use await ...
})();
]]></action>


But note - async, await is only syntactical sugar for promises and callbacks, there is no real asynchronous processing.
For such web-workers would need to be used.