Package com.thalesgroup.gemalto.d1
Class Task<T>
java.lang.Object
com.thalesgroup.gemalto.d1.Task<T>
- Type Parameters:
T- the type of result produced by this task
Represents an asynchronous unit of work that produces a result of type
T.
Note: Task instances should only be obtained from D1 SDK services
(such as PushProvisioningService).
To execute the task:
- Recommended: Use
await()(defined in TaskExtension.kt) in Kotlin for idiomatic Kotlin async handling. - Use
execute(D1Task.Callback)orexecute()in Java to start and get the results.
Example usage in Kotlin. In this example, the task is obtained from PushProvisioningService:
// Obtain task from PushProvisioningService
activity.lifecycleScope.launch(Dispatchers.Main) {
try {
val task = pushProvisioningServiceInstance.addDigitalCardToScheme(cardID, tokenRequestor, appURL, tcsAccepted)
val result = task.await()
//Handle result
} catch (e: D1Exception) {
//Handle error
}
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Texecute()Executes the task synchronously.voidexecute(D1Task.Callback<T> callback) Executes the task asynchronously and notifies the given callback upon completion.
-
Constructor Details
-
Task
public Task()
-
-
Method Details
-
execute
Executes the task asynchronously and notifies the given callback upon completion.Example usage. In this example,
taskis aTask<String>:task.execute(new D1Task.Callback<String>() { @Override public void onSuccess(String result) { // Handle result } @Override public void onFailure(D1Exception e) { // Handle failure } });- Parameters:
callback- The callback to receive the result or error.
-
execute
Executes the task synchronously.Example usage. In this example,
taskis aTask<String>:String result = null; try { result = task.execute(); } catch (D1Exception e) { //Handle error }- Returns:
- the result of type
Tof the task execution - Throws:
D1Exception- if the task fails during execution
-