Skip to content

Threads

Filip Vašš edited this page Sep 4, 2023 · 5 revisions

Most of the CM SDK work is slow (in terms of threads) or contains communication to remote servers. To improve user experience of integrating application, operating systems are recommending (or enforcing) these task not to run on a main (UI) thread - work have to be done on a background thread.

Methods in CM SDK (all in iOS and most of them in Android) are designed with callbacks for returning results. Callbacks contain means for passing successful and error result back to application. Asynchronous methods in CM SDK will switch to background thread to do the slow task and switch back to main thread before calling result callback.

Android

Synchronous Java methods are returning positive results. Error states are reported by throwing CMException or one of its subclasses (see Errors).

Synchronous Kotlin methods are returning positive and negative results by Either instance.

Asynchronous Java methods require instance of listener interface as parameter. Interface contains methods (one for positive, one for negative) for passing results back to caller.

iOS

Synchronous Swift methods are returning positive and negative results by Result instance.

Asynchronous Swift methods require completion block as parameter. Completion block accepts Result instance, which is used for passing results back to caller.

Possibly helpful information: Other useful stuff

Clone this wiki locally