According to the documentation of ProcessCameraProvider https://developer.android.com/reference/androidx/camera/lifecycle/ProcessCameraProvider#getInstance(android.content.Context) the call to getInstance(context) returns a ListenableFuture<ProcessCameraProvider> and the cancellation of this future is no-op. But if you cancel this future and try to call the ProcessCameraProvider.getInstance(context) again, it would return the ListenableFuture that is already canceled (it happens for all subsequent calls to this method). Is this how it really should be? If so, how should I handle the cancellation of a coroutine in which ProcessCameraProvider.getInstance(context) is called?
https://github.com/Kotlin/kotlinx.coroutines/blob/master/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt
In the documentation to await function there is a note saying: “If cancelling the given future is undesired, use [Futures.nonCancellationPropagating] or [kotlinx.coroutines.NonCancellable]”
I’ve tried to wrap the returned value of ProcessCameraProvider.getInstance(context) into Futures.nonCancellationPropagating and pass it to the await. It worked, but usage of Futures.nonCancellationPropagating is restricted to library group:
“Futures.nonCancellationPropagating can only be called from within the same library group”, so I need to add the @SuppressLint(“RestrictedApi”). Is it ok? How else should I handle the case, when cancellation of coroutine cancels the ListenableFuture returned from ProcessCameraProvider.getInstance(context)?
kotlinx.coroutines integration with ListenableFuture
Alabama Boy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.