Skip to content

Instantly share code, notes, and snippets.

View Vignesh150493's full-sized avatar

Vignesh Ramakrishnan Vignesh150493

View GitHub Profile
interface SchedulerProvider {
fun computation(): Scheduler
fun io(): Scheduler
fun ui(): Scheduler
fun single(): Scheduler
class MainController {
fun getItems() : List<Item> {
val apiResponse = getItemsFromApi()
val dbResponse = getItemsFromDb()
return Observable.concatArray(getItemsFromDb().toObservable(), getItemsFromApi().toObservable())
.onErrorReturn {
listOf()
}
import java.time.LocalDateTime
class Boy {
infix fun name(name : String) {
println("His name is $name")
}
}
fun main(args : Array<String>) {
val boy = Boy()
@Vignesh150493
Vignesh150493 / NetworkManager.kt
Created July 6, 2019 17:57
Network Manager - Auto observe network state
import com.github.pwittchen.reactivenetwork.library.rx2.Connectivity
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.FlowableTransformer
import io.reactivex.Observable
import com.rv.user.networkerrorretrier.Result
interface NetworkManager {
/**
* Exception used to denote that an operation was performed when network was not available.
@Vignesh150493
Vignesh150493 / Subscriber.kt
Created July 4, 2019 09:26
Sample subscriber for RxBus
eventBus.observeEventOnUi<EventTypeOne>()
.map { //Do any transformation if you want to! Bonus! }
.subscribe {
// Subscriber
}
eventBus.observeEventOnUi<EventTypeTwo>()
.subscribe {
// Subscriber
}
@Vignesh150493
Vignesh150493 / RxBus.kt
Last active July 15, 2019 03:53
EventBus Implementation
/**
* [EventBus] implementation backed by a [PublishProcessor]
*/
class RxBus : EventBus {
private val publishProcessor = PublishProcessor.create<Any>()
override fun postEvent(event: Any) {
publishProcessor.onNext(event)
}
@Vignesh150493
Vignesh150493 / EventBus.kt
Created July 3, 2019 17:35
Event bus contract defining method for a pub/sub system.
/**
* Events are posted to common bus and all active subscribers are notified of changes. Threading and
* backpresssure can be handled by subscribers.
*/
interface EventBus {
/**
* Post an event to bus.
*/
fun postEvent(event: Any)