How it works...

The preceding code is going to print the following text to the console:

Running on main
Starting async operation on Thread-0
Starting async operation on Thread-1
Ending async operation on Thread-1
Ending async operation on Thread-0

As you can see, we have successfully started two background threads, which are running concurrently. We are using the thread() utility function from the kotlin.concurrent package, which is responsible for instantiating and starting a new thread that runs a block of code passed to it in the form of a lambda expression.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.211.21