Creating Flowable from scratch

We learned about the Observable.create method in the previous chapter, but to make things less complicated, let's have a quick recap, and then we can continue with Flowable.create. Take a look at the following piece of code:

 fun main(args: Array<String>) { val observer: Observer<Int> = object : Observer<Int> { override fun onComplete() { println("All Completed") } override fun onNext(item: Int) { println("Next $item") } override fun onError(e: Throwable) { println("Error Occured ${e.message}") } override fun onSubscribe(d: Disposable) { println("New Subscription ") } }//Create Observer val observable: Observable<Int> = Observable.create<Int> {//1 for(i in 1..10) { it.onNext(i) } it.onComplete() } observable.subscribe(observer) ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.