August 2018
Beginner
178 pages
4h 56m
English
Doing some work in a different thread can be done in Kotlin the same as in Java, by creating an instance of the Thread class with a Runnable function and then starting it. Kotlin also offers a shortcut function called thread that is a little bit easier to use. It has several default parameters and only needs a lambda that will be executed in the newly created thread:
thread { //something long running println("Work done")}
This is how the thread function is defined in the standard library:
/** * Creates a thread that runs the specified [block] of code. * * @param start if 'true', the thread is immediately started. * @param isDaemon if 'true', the thread is created as a daemon thread. The Java Virtual Machine exits when * ...
Read now
Unlock full access