Code Monkey home page Code Monkey logo

Comments (14)

thuytrinh avatar thuytrinh commented on August 19, 2024

Speaking of emitting cursor rows, what do u think of wrapping the cursor with Iterable<Cursor>, then just call Observable.from(new IterableCursor(cursor). The IterableCursor looks like this https://gist.github.com/thuytrinh/0cec49eabac5b7f13f78.

from rxandroid.

JakeWharton avatar JakeWharton commented on August 19, 2024

Seems like a needless allocation. It also doesn't handle closing.
On Nov 21, 2014 8:15 PM, "Thuy Trinh" [email protected] wrote:

Speaking of emitting cursor rows, what do u think of wrapping the cursor
with Iterable, then just call Observable.from(new
IterableCursor(cursor). The IterableCursor looks like this
https://gist.github.com/thuytrinh/0cec49eabac5b7f13f78.


Reply to this email directly or view it on GitHub
#71 (comment).

from rxandroid.

mttkay avatar mttkay commented on August 19, 2024

I think the Iterator wrapper for Cursor is great. That's what we do in
Propeller. We do auto close cursors too. There's a bunch of reasons why
this is preferable to plain cursors (duality with observables and thus a
symmetric API for sync and async, interface parity with Java collections so
you can for instance apply Guava functions to Cursors)

from rxandroid.

AndrewReitz avatar AndrewReitz commented on August 19, 2024

How about something like https://gist.github.com/pieces029/076ddfe7122fd78da5a3?

from rxandroid.

dpsm avatar dpsm commented on August 19, 2024

So basically we want an Observable that emits an Iterable once and before completing closes the Cursor?

from rxandroid.

mttkay avatar mttkay commented on August 19, 2024

No it's just an adapter. As per the duality principle, anything that's
Iterable is also observable out of the box. That's how observables were
designed... Of course you could also write the iteration code yourself.
Actually, probably that is simpler here since we never need the properties
of Iterable but would just use it to piggy back the cursor.

from rxandroid.

dpsm avatar dpsm commented on August 19, 2024

@mttkay then if we do that then something like Observable.from(new IterableCursor(cursor)) will emit the Cursor already while it has next. With that said, all we need to do is close the cursor with something like:

Observable.from(new IterableCursor(cursor))
        .doOnCompleted(new Action0() {
            @Override
            public void call() {
                cursor.close();
            }
        });

Same for error so we always close the Cursor... Did I follow you correctly?

I guess our ContentObservables.query(..) could compose the Observable and add the closing cursor part there?

from rxandroid.

ronshapiro avatar ronshapiro commented on August 19, 2024

At Venmo we worked on an IterableCursor library, feel free to check it out https://github.com/venmo/cursor-utils. It works well with Rx, as it will emit regular T objects instead of just the cursor again. We could probably create a CursorObservable.from(IterableCursor) which calls the appropriate method (doOnTerminate() I think) to close the cursor.

from rxandroid.

mttkay avatar mttkay commented on August 19, 2024

@ronshapiro nice, I wrote almost the exact same thing for our storage abstraction

from rxandroid.

naixx avatar naixx commented on August 19, 2024

Shouldn't the examples above use Subscription to close the cursor?

from rxandroid.

JakeWharton avatar JakeWharton commented on August 19, 2024

This has been removed as part of #172 for a future release. Consider building on SqlBrite's ability to query a content resolver (not that I'm biased...).

from rxandroid.

djensen47 avatar djensen47 commented on August 19, 2024

I'm wondering if BackpressureBufferLastOperator from SqlBrite would make sense to include in RxAndroid. Nothing about it seems specific to SqlBrite. No?

from rxandroid.

f2prateek avatar f2prateek commented on August 19, 2024

Nothing about BackpressureBufferLastOperator is specific to Android either.

from rxandroid.

djensen47 avatar djensen47 commented on August 19, 2024

Nothing about BackpressureBufferLastOperator is specific to Android either.

Yeah, I was thinking that too. Add it to RxJava?

from rxandroid.

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.