Improve MessagePacket<*, *>.nextMessage

This commit is contained in:
Him188 2020-02-21 22:59:52 +08:00
parent 06381e8ba2
commit 2b7b8fa6c1

View File

@ -162,10 +162,10 @@ fun MessagePacket<*, *>.isContextIdenticalWith(another: MessagePacket<*, *>): Bo
suspend inline fun <reified P : MessagePacket<*, *>> P.nextMessage(
timeoutMillis: Long = -1,
crossinline filter: P.(P) -> Boolean
): P {
): MessageChain {
return subscribingGet<P, P>(timeoutMillis) {
takeIf { this.isContextIdenticalWith(this@nextMessage) }?.takeIf { filter(it, it) }
}
}.message
}
/**
@ -179,8 +179,8 @@ suspend inline fun <reified P : MessagePacket<*, *>> P.nextMessage(
*/
suspend inline fun <reified P : MessagePacket<*, *>> P.nextMessage(
timeoutMillis: Long = -1
): P {
): MessageChain {
return subscribingGet<P, P>(timeoutMillis) {
takeIf { this.isContextIdenticalWith(this@nextMessage) }
}
}.message
}