These are chat archives for ReactiveX/RxJava

21st
Jun 2016
Toon Sevrin
@toonsevrin
Jun 21 2016 17:36

Hey folks, I am just starting out with RxJava and am trying to implement it as an event bus.
Is is very bad practice to pass Cancellable events through the bus (these events are mutable, and after being processed the behaviour is result or not)?
If it's ok how can I subscribe with a priority in the call iteration?

I would really appreciate any help that can be given! Thanks guys!

The bus is currently a PublishSubject btw ;)
Dorus
@Dorus
Jun 21 2016 17:39
@stink123456 Observables are always cancellable. You can just push observables trough.
cancel is just unsubscribe.
Darius Lapūnas
@DariusL
Jun 21 2016 17:39
Well, if your bus can have many listeners and the items are mutable, you might run into trouble
Toon Sevrin
@toonsevrin
Jun 21 2016 17:41
@Dorus Oh lol, I meant cancelling the passed individual items (Setting a boolean on then that will be processed by the emitter)
@DariusL What would be the recommended approach?
@DariusL The API I used before this used annotations with an EventPriority enum.
Darius Lapūnas
@DariusL
Jun 21 2016 17:52
Depends on what you're trying to accomplish. IMO, if it's cancellable, it's not an event, it's a request. Then you need a queue, which is what most Schedulers are. If you want to use a bus, your events should be immutable, so that any number of listeners could handle them in their own ways without impacting each other.
Toon Sevrin
@toonsevrin
Jun 21 2016 18:02
Aah I see, that's the answer I was looking for, thanks a lot. An example could be a webApp with a request to display a page. The security extension/module could catch this request and if the user is not authorized, deny the request.
Darius Lapūnas
@DariusL
Jun 21 2016 18:04
yeah, if the order is important, there's no place for an even bus
Toon Sevrin
@toonsevrin
Jun 21 2016 18:05
So what would the recommended approach be if there are multiple actors on the request result (say if the security is allowed, the request will only pass after another module passes it)
You say some kind of queue right
There's probably a fundamental design flaw in this because actors have to know of each other to sort themselves in the right order :(