Asynchronous Custom Action

Creating an asynchronous custom action

Requirements:

  • A project set up with Beagle.
  • You need to have done the example for Custom Action.

Asynchronous custom action:

To create an asynchronous custom action in Beagle that works like an API, just create an actionlike the example in Custom Action and implement the AsyncAction interface.

After creating an action, you must implement the AsyncAction interface. It will request to execute a method and the onFinish parameter will be implemented.

struct CustomAction: AsyncAction {

        @AutoCodable
        var onFinish: [Action]?

        func execute(controller: BeagleController, origin: UIView) {

        }
    }

Now you MUST notify when its execution is completed by triggering the onFinish action.

controller.execute(actions: self.onFinish, origin: origin)

Follow the Asynchronous Custom Action example below:

struct CustomAction: AsyncAction {

        @AutoCodable
        var onFinish: [Action]?

        func execute(controller: BeagleController, origin: UIView) {
            print("Custom action was called")

            controller.execute(actions: self.onFinish, origin: origin)
        }
    }

Your action is now configured to perform any tasks asynchronously!