Skip to content

Instantly share code, notes, and snippets.

@esabook
Last active January 19, 2020 09:10
Show Gist options
  • Save esabook/f834499495e328cc762e938b8110723a to your computer and use it in GitHub Desktop.
Save esabook/f834499495e328cc762e938b8110723a to your computer and use it in GitHub Desktop.
EventBus wrapper in RxJava
package ***
import io.reactivex.subjects.PublishSubject
import java.util.*
class RxBus {
companion object {
val instance = RxBus()
private val subject = PublishSubject.create<Any>()
}
/**
* Pass any event down to event listeners.
*/
fun post(obj: Any){
subject.onNext(obj)
}
/**
* Subscribe to this Observable. On event, do something
* e.g. replace a fragment
*/
fun getEvent(): PublishSubject<Any>? {
return subject
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment