Other Observable factory methods
Before moving forward with Observer
, subscribing, unsubscribing, and Subjects
, let's try our hands on a few other factory methods of Observable
.
So, let's look at this code first, and then we will try to learn it line by line:
fun main(args: Array<String>) { val observer: Observer<Any> = object : Observer<Any> { override fun onComplete() { println("All Completed") } override fun onNext(item: Any) { println("Next $item") } override fun onError(e: Throwable) { println("Error Occured ${e.message}") } override fun onSubscribe(d: Disposable) { println("New Subscription ") } }//Create Observer Observable.range(1,10).subscribe(observer)//(1) Observable.empty<String>().subscribe(observer)//(2) runBlocking { Observable.interval(300,TimeUnit.MILLISECONDS). ...