Async Custom Action

Creating a custom async action

To create a custom action in Beagle where execution is asynchronous such as consuming an API or accessing a database, just create an action as usual as the previous example detailed and implement the AsyncAction interface.

With the action created, just link the AsyncAction interface and delegate its implementation to the AsyncActionImpl class that Beagle already provides.

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

Now, with the action ready to execute asynchronously, you have to MANDATORY notify when its execution is finished through the onActionFinished method.

@RegisterAction
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 11, 2021: create content (#298) (43225e15)