with Timeout
abstract fun <T> withTimeout(timeoutMillis: Long, block: CoroutineScope.() -> Deferred<T>): Deferred<T>
在指定的超时时间内运行代码块。如果超时,返回的 Deferred 将会因 TimeoutCancellationException 而失败。
这是一个非阻塞函数,它会立即返回一个 Deferred 对象。
Return
一个 Deferred
Parameters
T
代码块返回结果的类型。
timeout Millis
超时时间(毫秒)。
block
要在超时限制内执行的代码块。