There are certain scenarios when completing an activity upon completion of its function is not possible or desirable. For example, you might have an application that requires user input in order to complete the activity. You could implement the activity with a polling mechanism, but a simpler and less resource-intensive implementation is to asynchronously complete a Temporal activity.
There two parts to implementing an asynchronously completed activity:
- The activity provides the information necessary for completion from an external system and notifies the Temporal service that it is waiting for that outside callback.
- The external service calls the Temporal service to complete the activity.
The following example demonstrates the first part:
The following code demonstrates how to complete the activity successfully:
To fail the activity, you would do the following:
Following are the parameters of the
taskToken: The value of the binary
TaskTokenfield of the
ActivityInfostruct retrieved inside the activity.
result: The return value to record for the activity. The type of this value must match the type of the return value declared by the activity function.
err: The error code to return if the activity terminates with an error.
error is not null, the value of the
result field is ignored.