Drakon.Tech logo
Get started
Drakon.Tech documentationProgramming in DRAKONThe basics of programming with Drakon.TechAdvanced programming methodsasync/awaitState machinesModules and dependenciesHow to share your codeWorking with source controlGame examplesThe source codeLegacy tutorials (JavaScript 0.2)


Ru | En

Source code: Async/await

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

  1. Right-click on the function header.
  2. Choose "Properties."
  3. Set function type to "Async function."
How to make a function async in Drakon.Tech

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.

An example of an await expression in Drakon.Tech

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.

  1. Transform an async function into a silhouette.
  2. Choose a branch for error handling.
  3. Right-click on the diagram header and choose "Properties."
  4. Add this line to the parameters: on error goto BranchName.
How to catch an exception in an async function in Drakon.Tech

To get a reference to the error object in the handler branch, use getHandlerData() function.

Source code: Async/await
Drakon.Tech logo
Drakon.Tech home
Programming in DRAKONThe basics of programming with Drakon.TechAdvanced programming methodsThe source codeLegacy tutorials (JavaScript 0.2)