question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rx: StorIOContentResolver updates running on StorIOContentResolverNotificationsThread

See original GitHub issue

Hello, I’ve noticed that when using the StorIOContentResolver API, all emissions triggered by a contentResolver notifications come back on the same thread, so doing a long running operation on the same observable can delay notifications being received by another listener. For instance:

PreparedGetListOfObjects<> query = storIOSQLite
                .get()
                .listOfObjects(Tweet.class)
                .withQuery(TweetsTable.query)
                .prepare()

Subscription subA = query.asRxObservable()
         .doOnNext(tweets -> Log.d("TEST", "Logs immediately!"))
         .flatMap(tweets -> lonRunningObservable()) /* Say this runs for 10 seconds */
         .subscribe()


Subscription subB = query.asRxObservable()
         /* Delayed if notification was delivered to subscriber A*/
         .doOnNext(tweets -> Log.d("TEST", "Sometimes logs 10 seconds late!")) 
         .subscribe()
...

final List<Tweet> tweets = new ArrayList<Tweet>();
tweets.add(Tweet.newTweet("artem_zin", "Cool Tweet"));
storIOSQLite
     .put()
     .objects(tweets)
     .prepare()
     .asRxObservable()
     .subscribe();

I realize that it can be avoided by switching to another thread with observeOn(), but aren’t updates supposed to use the default (or specified) scheduler?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
artem-zinnatullincommented, May 14, 2017

@geralt-encore what do you think about proposal?

0reactions
nikitin-dacommented, May 24, 2017

internally moving the ContentObserver emission to the i/o pool

Since we should initially receive all notifications on the common handler thread (https://github.com/pushtorefresh/storio/blob/master/storio-content-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/impl/RxChangesObserver.java#L40) moving emission to thread from io pool will add delay due to thread switching =( If user will agree with such delay defaultObserveOnScheduler(Schedulers.io()) will do this trick If you prefer to manually configure schedulers on every case and get rid of such delay - simply use defaultObserveOnScheduler(null)

asRxObservable(Scheduler)

I’m not sure that asRxObservable(Scheduler) will give more benefits over asRxObservable().observerOn(Scheduler)

Read more comments on GitHub >

github_iconTop Results From Across the Web

pushtorefresh/storio: Reactive API for SQLiteDatabase and ...
Flowable from Get Operation will observe changes in StorIO ( SQLite or ContentProvider ) and receive updates automatically; StorIO is replacements for ...
Read more >
ContentResolver | Android Developers
An extension of ContentResolver that is designed for testing. ... to indicate that this notification is the result of an ContentProvider#update call.
Read more >
070: An honest discussion about Realm - Fragmented Podcast
In this episode they have an honest and frank discussion about using Realm, the advantages, the disadvantages, the gotchas and if it makes...
Read more >
Does `context.contentResolver.query()` run on UI thread?
I am working on a application to get call logs, I am finding it hard to find if context.contentResolver.query() runs on UI thread...
Read more >
awesome-java - CD2H gitForager
Description: A curated list of awesome Java frameworks, libraries and software. Created: 2015-08-12 17:56:04.0. Updated: 2018-05-21 00:08:30.0.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found