Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Throws(InterruptedException::class)
- fun <T> LiveData<T>.getValueBlocking(): T? {
- var value: T? = null
- val latch = CountDownLatch(1)
- val innerObserver = Observer<T> {
- value = it
- latch.countDown()
- }
- observeForever(innerObserver)
- latch.await(2, TimeUnit.SECONDS)
- return value
- }
Add Comment
Please, Sign In to add comment