Async Functions

Use async functions to ensure that your custom functions execute exactly as you intend

What are async functions?

When working with custom functions in Xano, you can choose to have them execute asynchronously. An async function works like a background task, allowing your main process to continue without waiting for the custom function to finish.

When should I use async functions?

Asynchronous execution can be particularly beneficial in scenarios where you don't want certain tasks to hold up the entire process. For instance, if you're running a complex data fetch or a time-consuming operation, doing it asynchronously means your main application or interface remains responsive to user inputs while the background operation continues independently. This can enhance user experience by reducing wait times.

Here are a few examples of when to use async functions:

  • Loading Data: When fetching data from a server, such as pulling in user information or loading a list of products, async functions allow the page to display its initial content quickly without waiting for the entire data request to complete.

  • File Uploads: Starting a file upload process without freezing the interface lets users continue interacting with the application while the file is being processed.

  • Notification Systems: Sending notifications through email or messaging services asynchronously ensures that users continue their tasks without interruption while the messages are sent in the background.

Using Async Functions

Once you've built your custom function and added it to another function stack, you have the option of running the function asynchronously. This just means that the functions will be queued for execution, and the rest of your function stack will continue to execute right away.

Asynchronous functions will utilize your background task resources (unless you are on a Custom or Enterprise plan), so it's important to manage expectations when it comes to execution speed. It would be most appropriate to use asynchronous functions when you need to trigger an operation as part of a larger function stack, but do not need to reference the output in the same stack.

Parallel execution of your async functions (running more than one async function at a time) is handled by workers, and the number of workers scales with each Xano plan. Async functions are placed into a queue and they get processed by available workers β€” the more workers you have available, the more parallel executions can run.

Enabling Async Execution

1

Right-click on the custom function in your function stack, and choose Async Settings.

2

In the panel that opens, choose your desired execution type.

  • Synchronous is standard execution. Your function stack will allow the custom function to finish executing before continuing.

  • Async and Async (dedicated) allow for running custom functions in the background while the rest of the function stack continues to execute.

Types of Async Execution

1

Async

This option runs your functions asynchronously using your background task resources. Performance may vary based on other tasks being executed and the Xano plan you are currently on.

2

Async (dedicated)

This option is available for our Custom and Enterprise plans. It enables you to utilize dedicated resources to execute your custom functions asynchronously, and to specify the volume of resources to use. On a Custom or Enterprise plan, you have enhanced functionality to leverage these on-demand resources (instead of your background task resources) for each worker. Each function gets their own dedicated worker, with no queueing system. This allows you to support scenarios like parallel processing with thousands of workers, if necessary.

When choosing Async (dedicated), you'll have four options of resource allocation:

  • Small - Good for small operations with just a few data points or quick transformations

  • Medium - Handles more moderate workloads, such as working with a few hundred data points

  • Large - For larger datasets, such as working with thousands of points of data or database records

  • Custom - Allows you to define your own resource allocation if you have specific requirements

When using async functions, the function request history will still populate, so you can review the requests once they have finished executing. Each request will be labeled with the execution method.

Using Async Function Await

This function allows you to retrieve the output of a custom function executed asynchronously.

1

Insert a custom function into your function stack.

If you haven't built any custom functions yet, you can review our documentation on them here.

2

Click on the function to change the execution mode.

3

If necessary, retrieve the output of the async function.

If a function is set to async, it will return an ID that represents that execution, similar to the value shown below.

6f10cc09-d3e0-4ead-9a98-a0bc66bbe673

You can use the Async Function Await function to retrieve the output of the function once execution completes. Just provide it with an array of the ID(s) returned when the function runs.

Last updated

Was this helpful?