Hi there I want to write a useful function to do w...
# android
j
Hi there I want to write a useful function to do waiting a condition come true with timeout. For example :
Copy code
/***
* I dont know when `condition` come true but It will be true after waiting 3,4 seconds time
* So I want to wait until condition come true . If not come true within 1minutes throw timeoutException
***/

fun execute {
  withTimeout(10_000) {
      while (true) {
         if(condition == true) -> cancel timeout then using condition in next step
      }
  }
  
  // Next step
  condition is true and I will handle it.
}
How to implement this function in Kotlin?