This class should be used by the sdk manger to expose a functionally and handle multithreading as well,
Usually we expose the repository methods.
Why?
As of now due to some limitations in some platform like JS and Java we can not use suspend, therefor exposing suspended functions directly form the sdk’s client manger will not work
Using a wrapper class such as Task will provide a unified approach for multithreading by providing interfaces like await() and get() and other callbacks
Create a Task
To create a task we just need to invoke Task.execute , provide a return type and our logic goes inside the body block
Use a Task
There is two ways to get the result from a task
Callbacks
In all platforms (except java) you can use the following callbacks
Suspended (blocking)
You can still use the task as suspended to use inside your coroutines, Or in a blocking approach in languages like java and javascript
Called when a task is done and successful, you can use the result in main thread so you can make UI operations (hide loaders), Both onSuccessonSuccessUI will be invoked
if the task failed , the result will be a ClientExcecptoin , if it was an api call you will get the http status and url that failed in case multiple api calls were made
if task failed , the result will be a ClientExcecptoin , use this callback to update the UI in main thread (show error UI) the exception might hold the backend error message
Will be called after success, failure of cancel and return a nullable result or ClientExcecptoin depending on the outcome , To check if task was completed due to cancellation you can use isCancellationException —
Will be called after success, failure of cancel and return a nullable result or ClientExcecptoin depending on the outcome , To check if task was completed due to cancellation you can use isCancellationException Use this callback to update the UI in main thread (stop showing loaders) —