3

We're trying to observe either a 15s interval, or whenever we're firing onNext on our subject refreshEventsSubject, but without success.

The subject is initiated like so

private val refreshEventsSubject = PublishSubject<Long>()

And then we try to observe it like this

Observable.merge(Observable.interval(0, 15, TimeUnit.SECONDS), refreshEventsSubject) .subscribe { ... }

We get the events from the interval every 15s, but the subject is not firing after running

refreshEventsSubject.onNext(0)

Any ideas appreciated.

(Everything is written in Kotlin)

Hannes Lohmander
  • 1,315
  • 1
  • 8
  • 8
  • 1
    In RxJava, you create a `PublishSubject` via `PublishSubject.create()` static method because of creating one via a parameterless constructor doesn't work. I don't know if RxKotlin compensates for this or not. – akarnokd Nov 16 '16 at 12:18
  • 1
    Yes, the Kotlin rx binding for PublishSubject looks like this `fun PublishSubject() : PublishSubject = PublishSubject.create()` – Hannes Lohmander Nov 16 '16 at 12:49

2 Answers2

1

Make sure refreshEventsSubject.onNext(0) is not called from your main thread as it may cause deadlocks!

Also use http://reactivex.io/documentation/operators/amb.html rather than merge as merge will emmit two events oppon calling onNext on your subject.

Richard
  • 14,427
  • 9
  • 57
  • 85
0

Read the documentation for AMB: http://reactivex.io/documentation/operators/amb.html

Specifically emit all of the items from only the first of these Observables to emit an item or notification.

The operator you're looking for is probably Observable.merge: http://reactivex.io/documentation/operators/merge.html

Kiskae
  • 24,655
  • 2
  • 77
  • 74
  • Granted, it does however still not work. If we subscribe directly to the subject we get the event, but when combined/merged with the interval stream, nothing is happening. – Hannes Lohmander Nov 16 '16 at 11:36