Guest User

Untitled

a guest
Nov 21st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. @Throws(InterruptedException::class)
  2. fun <T> LiveData<T>.getValueBlocking(): T? {
  3. var value: T? = null
  4. val latch = CountDownLatch(1)
  5. val innerObserver = Observer<T> {
  6. value = it
  7. latch.countDown()
  8. }
  9. observeForever(innerObserver)
  10. latch.await(2, TimeUnit.SECONDS)
  11. return value
  12. }
Add Comment
Please, Sign In to add comment