Event bus framework supports sticky events and subscribers' priority based on RxJava 3.x
This library is distributed by jitpack.
You should add jitpack maven repository to build.gradle file of your project.
repositories {
...
maven { url 'https://jitpack.io' }
...
}
Then you can include this library by adding dependency script to build.gradle file of your project.
dependencies {
...
compile 'com.github.ridi:rxbus:<version>'
...
}
class Event(val value: Int) {
override fun toString() = "{value=$value}"
}
RxBus.asObservable(Event::class.java).subscribe { e ->
System.out.println(e.toString())
}
RxBus.post(Event(0))
Output
{value=0}
Sticky event
RxBus.postSticky(Event(0))
RxBus.asObservable(Event::class.java, sticky = true).subscribe { e ->
System.out.println(e.toString())
}
RxBus.post(Event(1))
Output
{value=0}
{value=1}
RxBus.asObservable(Event::class.java, priority = -1).subscribe { e ->
System.out.println("-1 Priority : $e")
}
RxBus.asObservable(Event::class.java, priority = 1).subscribe { e ->
System.out.println("1 Priority : $e")
}
RxBus.asObservable(Event::class.java).subscribe { e ->
System.out.println("Default(0) Priority : $e")
}
RxBus.post(Event(0))
Output
1 Priority : {value=0}
Default(0) Priority : {value=0}
-1 Priority : {value=0}