Task
Asynchronous Task
When interacting with the scanner, we usually don't want to block the main thread Instead we want to e.g. update the UI and use the result once it is available
Since we are supporting multiple platforms, we have to use Kotlin coroutines, which support every platform to some extent. The only function that is not available on JS is runBlocking, that's why this Task does not support being compiled to JS
Getting the result
The first way of receiving the result of a task is by using await. This will block the coroutine execution until the result is available or an exception is thrown. This is only available in a Coroutine Context.
The second way is by using onComplete, onSuccess or onError. By using these methods, we are not blocking and instead are executing the task asynchronously Once a result is received, the result can be used in the closure
Constructors
Properties
defines whether task has completed. Completed does not mean that it was successful, only that there is no work to do anymore.
The result of the task. Should only be called once Task finished indicated by isComplete. Use onComplete, waitForResult or await to ensure that.
Functions
Lambda is called once task has completed. You can then check .result for successful result or it will throw an error. Returns Task.
Waits for the result of the current task, without caring about the result or an error. It won't return the result neither will it throw. You have to call Task.result for this.