All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fireflysource.common.coroutine.ChannelExtension.kt Maven / Gradle / Ivy

The newest version!
package com.fireflysource.common.coroutine

import kotlinx.coroutines.channels.Channel

inline fun  Channel.consumeAll(crossinline block: (T) -> Unit) {
    try {
        while (true) {
            val result = this.tryReceive()
            if (result.isFailure) {
                break
            }
            val message = result.getOrNull() ?: break
            block(message)
        }
    } catch (ignore: Exception) {
    }
}

fun  Channel.clear() {
    this.consumeAll { }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy