Async operations

All CRUD-operations executed synchronously, but you can also execute the operations asynchronously:

Select.<your operators>.fetchAsync(); //returns Single

Select.<your operators>.fetchSingleAsync(); //returns Single

Insert.<your operators>.executeAsync(); //returns Completable

Update.<your operators>.executeAsync(); //returns Completable

Delete.<your operators>.executeAsync(); //returns Completable

For async operations ReActiveAndroid uses RxJava 2, so to start an operation you should specify a Scheduler and call the subscribe() method:

Select.from(Note.class).fetchSingleAsync()
    .subscribeOn(Schedulers.io())
    .subscribe(note-> {});


Delete.from(Note.class).executeAsync()
    .subscribeOn(Schedulers.io())
    .subscribe();

The same applies to Model methods:

myNote.saveAsync()
    .subscribeOn(Schedulers.io())
    .subscribe();


myNote.deleteAsync()
    .subscribeOn(Schedulers.io())
    .subscribe();

If you want to get an operation result in the UI thread you should use the AndroidSchedulers class from RxAndroidLibrary:

myNote.saveAsync()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe();

results matching ""

    No results matching ""