The ReactiveCalculator class with coroutines

So far, in the ReactiveCalculator program, we were performing everything on the same thread; don't you think we should rather do the things asynchronously? So, let's do it:

    class ReactiveCalculator(a:Int, b:Int) { 
      val subjectCalc:      io.reactivex.subjects.Subject<ReactiveCalculator> = io.reactivex.subjects.PublishSubject.create() var nums:Pair<Int,Int> = Pair(0,0) init{ nums = Pair(a,b) subjectCalc.subscribe({ with(it) { calculateAddition() calculateSubstraction() calculateMultiplication() calculateDivision() } }) subjectCalc.onNext(this) } inline fun calculateAddition():Int { val result = nums.first + nums.second println("Add = $result") return result } inline fun calculateSubstraction():Int { val ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.