Solution: Dispatchers
See the solution to the problem presented in the challenge.
We'll cover the following...
We'll cover the following...
Solution
The solution to the challenge we just solved is as follows.
var i = 0 suspend fun main(): Unit = coroutineScope { val dispatcher = Dispatchers.Default .limitedParallelism(1) repeat(10000) { launch(dispatcher) { i++ } } delay(2000) println(i) }
Solution to the challenge
Explanation
Here is a line–by–line explanation of the code above:
-
...