Skip to content

Async Functions

Async functions allow you to work with asynchronous operations like API requests, timeouts, and other promises using the await keyword.

By enabling the async mode for a function, you can write cleaner, more readable code when dealing with asynchronous operations.

Enabling Async Mode

To make a function asynchronous:

  1. Open the function configuration
  2. Navigate to the Function Code section
  3. Check the Async? checkbox below the code editor

Async function

Once enabled, your function automatically becomes async and you can use await within the function body.

When to Use Async Functions

Use async functions when you need to:

  • Wait for API requests to complete before processing the response
  • Perform multiple sequential asynchronous operations
  • Use await with promises
  • Call other async functions

Async Functions and Return Values

Async functions automatically wrap their return value in a Promise. When you call an async function, the caller receives a Promise that resolves to the returned value.

javascript
// This async function returns a Promise
const result = await f.myAsyncFunction();
// The result is the actual value, not the Promise

TIP

Learn more about async functions in the MDN documentation.