Reputation: 406
I have an Android service that downloads files when a PublishSubject receives download events through EventBus and I want to limit the number of concurrent downloads based on a setting.
When the service is instantiated, it creates the PublishSubject and the following subscription:
PublishSubject<DownloadEvent> downloadsSubject = PublishSubject.create();
Subscription downloadSubscription = downloadsSubject
.subscribeOn(Schedulers.io())
.filter(event -> !isDownloaded(event))
.flatMap(this::addDownloadToQueue)
.flatMap(this::startDownload, preferences.getDownloadThreadsNumber())
.onBackpressureBuffer()
.subscribe();
But the setting is obtained only when the subscription is made, and changes to the setting have no effect.
Is there a way to update this value (or another approach) for next queue emissions without having to subscribe again?
Upvotes: 2
Views: 265