WorkManager: FutureCallback always returns success no matter what result

201 Views Asked by At

I am doing this:

val fileUploadRequest = OneTimeWorkRequestBuilder<FileUploadWorker>().build()

Futures.addCallback(workManager.enqueueUniqueWork(this::class.simpleName!!, ExistingWorkPolicy.KEEP, fileUploadRequest).result,
    object : FutureCallback<Operation.State.SUCCESS> {
        override fun onSuccess(result: Operation.State.SUCCESS?) {
            Log.d(TAG, "onSuccess: ")
        }

        override fun onFailure(t: Throwable) {
            Log.d(TAG, "onFailure: ")
        }
    },
    executor
)

with this RxWorker code:

override fun createWork(): Single<Result> {
        return Single.just(Result.failure())
}

I always end up in onSuccess(). How come?

Also: Is the Futures callback ever removed? Or does it live forever? Do I need to remove it manually during some circumstances?

0

There are 0 best solutions below