Skip to content
Event bus framework supports sticky events and subscribers' priority based on RxJava 2.x
Kotlin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
src
.editorconfig
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat

README.md

RxBus

Build Status Release

Event bus framework supports sticky events and subscribers' priority based on RxJava 2.x

Getting started

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

How to use

Defining event class

class Event(val value: Int) {
    override fun toString() = "{value=$value}"
}

Event subscription/posting

RxBus.asObservable(Event::class.java).subscribe { e ->
    System.out.println(e.toString())
}
RxBus.post(Event(0))

Output

{value=0}

Sticky events

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}

Subscription priority

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}
You can’t perform that action at this time.