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 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.