Giter Site home page Giter Site logo

Comments (6)

npurushe avatar npurushe commented on May 7, 2024

Hi. The issue here is delete().get() just creates the operation of type Scalar<Integer> that has to evaluated. You can evaluate it by calling value() or consume(Consumer<? super E> action). Something like:

Integer rowsDeleted = MyApplication.getInstance().getData().toBlocking().delete(City.class).get().value();
List<City> wasCities=MyApplication.getInstance().getData().select(City.class).get().toList(); // will be empty now

Will make this more clear in the examples and documentation. Sorry about any confusion. Thanks for reporting!

from requery.

oleonov avatar oleonov commented on May 7, 2024

Thanks! Looks complicated)

from requery.

npurushe avatar npurushe commented on May 7, 2024

The reason for that is the API is designed to be fully non-blocking/reactive. I agree its a little bit more complicated in blocking use cases, there will be some improvements there

from requery.

oleonov avatar oleonov commented on May 7, 2024

I know, but using retrofit+rxAndroid I need blocking operation inside onNext. How can I do it simpler?

NetworkApi.getServerApi().getCities()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<City>>() {
                    @Override
                    public void onCompleted() {
                        sendBroadcast(new Intent(BroadcastHelper.ACTION_CITY_LOADED));
                        System.out.println("onCompleted");
                    }

                    @Override
                    public void onError(Throwable e)
                    {
                        ...
                    }

                    @Override
                    public void onNext(List<City> cities) {
                        System.out.printf("onNext %s\n", cities);
                        if(cities!=null)
                        {
                            MyApplication.getInstance().getData().toBlocking().delete(City.class).get().value();
                            MyApplication.getInstance().getData().toBlocking().insert(cities);
                        }
                    }
                });

from requery.

npurushe avatar npurushe commented on May 7, 2024

I'm not sure that's what you want because then you are doing the database operations on the main thread then. You probably want to use the rx map() operator to apply functions to the observable which can do the database work before the final subscription.

from requery.

oleonov avatar oleonov commented on May 7, 2024

Thank you! I did so and get more speed for UI.

from requery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.