在withTimeout()块中使用时,Kotlin channel.receive()不会超时

时间:2019-03-14 13:03:21

标签: kotlin kotlin-coroutines

当频道在特定时间后未收到消息时,我希望channel.receive()超时以执行其他操作。

我尝试使用withTimeout()块,但实际上并没有超时。

val incomingNotification = withTimeout(1000L) {
    (session.outgoing as Channel<Frame>).receive()
}

难道receive()实际上不可取消吗? 我在做什么错了?

0 个答案:

没有答案