Reputation: 868
I want to return true or false from Single.fromCallable{} in RxJava.Is there any other way to achieve it
private isBlockListAvailable():Boolean
{
Single.fromCallable {
//** data base query
blockRepo.getAllBlocks()
}.subscribeOn(Schedulers.io())
.subscribe({blockList : List<BlockList>
if (blockList> 0) {
return true // how can i achieve this
} else {
return false // how can i achieve this
}
})
}
Thanks in Advance:)
Upvotes: 0
Views: 2144
Reputation: 795
No, you cant. It's impossible to return value in the subscribe method. Look detail at its implementation.
Single.subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
}
})
You can see the method accept of the Consummer class is a type of void. Obviously, it cant return value.
Another way, you can create Single.fromCallable if you prefer to manipulate boolean in subscribe.
Upvotes: 1