Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.29 KB | None | 0 0
  1.  
  2.     fun <T> executeTimeout(executor: Executor, timeoutMs: Long, block: () -> T): T? {
  3.         var t: T? = null
  4.         val latch = CountDownLatch(1)
  5.         executor.execute { t = block(); latch.countDown() }
  6.         latch.await(timeoutMs, TimeUnit.MILLISECONDS)
  7.         return t
  8.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement