Reputation: 6295
I want to run a method in background using rxjava. I don't care about the result.
void myHeavyMethod() { (...) }
So far the only solution I have is to modify the return type to e.g. boolean
.
boolean myHeavyMethod() { (...) return true; }
Afterwards I run:
Completable.defer(() -> Completable.fromCallable(this::myHeavyMethod))
.subscribeOn(Schedulers.computation())
.subscribe(
() -> {},
throwable -> Log.e(TAG, throwable.getMessage(), throwable)
);
Is there a way to do it keeping the void
return type?
Upvotes: 22
Views: 8308
Reputation: 39863
The fromAction()
method is what you're looking for.
Completable.fromAction(this::myHeavyMethod)
Upvotes: 44