async/await
Ru | En
Drakon.Tech supports await expressions. The await keyword is only allowed in async functions.
You can use external JavaScript functions that return Promises in await expressions in Drakon.Tech. You can use Drakon.Tech async functions in await expressions in external JavaScript code.
How to make a function async in Drakon.Tech
- Right-click on the function header.
- Choose "Properties."
- Set function type to "Async function."
In this example, we call a REST endpoint using the await keyword. Calling a web service is an excellent example of a long-running operation that benefits from await. Awaiting does not block the JavaScript engine, and the browser can process other events in the meantime.
In Drakon.Tech, async functions are state machines that can accept messages. In other words, async functions in DrakonTech allow for automata-based programming. However, you don't need to think about that unless you intend to send information to long-running functions.
How to catch exceptions in async functions
Drakon.Tech does not allow the try-catch construct in async functions. To catch exceptions in an async function, use the on error goto X expression.
- Transform an async function into a silhouette.
- Choose a branch for error handling.
- Right-click on the diagram header and choose "Properties."
- Add this line to the parameters: on error goto BranchName.
To get a reference to the error object in the handler branch, use getHandlerData() function.