Closed Raenar4k closed 6 years ago
Docs from await
: Blocks current thread until result is available.
. So please use it in a thread.
Regarding toObservable
looks like you also block main thread too and you call takePicture
from that (main) thread.
So you need to use different threads:
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Ah, my bad! Thanks for quick response. Yep, it works alright, when triggered in non UI thread.
I did expect it to block, but return some result eventually.
As to why callback never gets delivered:
~onPictureTaken()
callback is called on main thread. takePicture
method is also executed on main thread and ~it seems to block thread until callback is called~ -> callback can not be called since the thread is blocked by takePicture
method -> and so it is never returned~
Update: read explanation below. Blocking is done by future.get()
method
.await()
the task will be executed and result will be reported on same thread.whenAvailable
the task will be executed on a background thread but result will be reported on main thread.When main thread is blocked because it's waiting the result no other operation can be executed e.g. taking picture itself internally.
Now it makes sense to me! Thanks :)
What are you trying to achieve or the steps to reproduce?
I am trying to use fotoapparat Rx adapters to work with the result or get result directly from pendingResult.await() method. Both are causing camera to freeze.
I've reproduced this issue in sample project, using version from
master
branch or from2.2.0
tag. You can use either method and take a photo from back camera to reproduce this.Here im using await() method:
And here is the example same as in fotoapparat-adapters readme, using rxjava2:
Using
toFlowable()
ortoObservable()
produces same result.How did you initialize FA?
Sample project looks like this (shortened):
Context: