Async Custom Action

In this section, you will find how to create a custom async action.

Topics covered:

  • How to create an Async Action

Requirements:

How to create Assyn Actions

To create an action with asynchronous execution such as consuming an API or accessing a database, follow the steps:

Step 1: Create an action as usual, just like the previous example;
Step 2: Implement the AsyncAction interface;
Step 3: Link the AsyncAction interface and delegate its implementation to the AsyncActionImpl class provided by Beagle.

@RegisterAction("customActionAndroid")
data class CustomActionAndroid(
    val value: String
) : Action, AsyncAction by AsyncActionImpl() {
    override fun execute(rootView: RootView) {
        // Do asynchronous work
    }
}

Step 4: Now, the action is ready to execute asynchronously. It is MANDATORY to notify when the execution is finished through the onActionFinished method.

@RegisterAction("customActionAndroid")
data class CustomActionAndroid(
    val value: String
) : Action, AsyncAction by AsyncActionImpl() {
    override fun execute(rootView: RootView) {
        // Do asynchronous work
        onActionFinished()
    }
}

It’s done! Your action is now configured to run any job asynchronously!


Last modified February 15, 2022: fix: Update/async actions (#840) (c4d57bd1)