Skip to main content
Glama
MaestroTimer.kt1.28 kB
package maestro.utils object MaestroTimer { var sleep: (Reason, Long) -> Unit = { _, ms -> Thread.sleep(ms) } private set fun setTimerFunc(sleep: (Reason, Long) -> Unit) { this.sleep = sleep } fun <T> withTimeout(timeoutMs: Long, block: () -> T?): T? { val endTime = System.currentTimeMillis() + timeoutMs do { val result = block() if (result != null) { return result } } while (System.currentTimeMillis() < endTime) return null } fun retryUntilTrue( timeoutMs: Long, delayMs: Long? = null, onException: (Exception) -> Unit = {}, block: () -> Boolean, ): Boolean { val endTime = System.currentTimeMillis() + timeoutMs do { try { delayMs?.let { sleep(Reason.BUFFER, delayMs) } if (block()) { return true } } catch (ignored: Exception) { onException(ignored) } } while (System.currentTimeMillis() < endTime) return false } enum class Reason { WAIT_UNTIL_VISIBLE, WAIT_TO_SETTLE, BUFFER, } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mobile-dev-inc/Maestro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server