Skip to content

Instantly share code, notes, and snippets.

@NikolaDespotoski
Created January 27, 2017 12:05
Show Gist options
  • Save NikolaDespotoski/c09ace9f13a58883ea8a0c9da6472498 to your computer and use it in GitHub Desktop.
Save NikolaDespotoski/c09ace9f13a58883ea8a0c9da6472498 to your computer and use it in GitHub Desktop.
Iterate Cursor in using RxJava
public class RxCursorIterable implements Iterable<Cursor> {
private Cursor mIterableCursor;
public RxCursorIterable(Cursor c) {
mIterableCursor = c;
}
public static RxCursorIterable from(Cursor c) {
return new RxCursorIterable(c);
}
@Override
public Iterator<Cursor> iterator() {
return RxCursorIterator.from(mIterableCursor);
}
static class RxCursorIterator implements Iterator<Cursor> {
private final Cursor mCursor;
public RxCursorIterator(Cursor cursor) {
mCursor = cursor;
}
public static Iterator<Cursor> from(Cursor cursor) {
return new RxCursorIterator(cursor);
}
@Override
public boolean hasNext() {
return !mCursor.isClosed() && mCursor.moveToNext();
}
@Override
public Cursor next() {
return mCursor;
}
}
}
@cyph3rcod3r
Copy link

Can we send batch of cursors lets say 10 at a time if yes how?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment