July 2018
Intermediate to advanced
266 pages
7h 11m
English
The next step will be to create an actor that will encapsulate the counter with the amount of news that has been found for the given search. Because this actor can be accessed from many areas, we will write it to be a singleton.
Let's create the Kotlin file ResultsCounter.kt in the package co.starcarr.rssreader.search and then create the singleton ResultsCounter inside it with a couple of properties:
object ResultsCounter { private val context = newSingleThreadContext("counter") private var counter = 0}
First we have context, which is a CoroutineContext that consists of a single thread. The coroutine of the actor will ultimately run with that context, so we will avoid atomicity violations by having all ...
Read now
Unlock full access