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

commonMain.dev.bluefalcon.NativeFlow.kt Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package dev.bluefalcon

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.plus

internal fun  Flow.toNativeType(scope: CoroutineScope): NativeFlow = NativeFlow(this, scope)

class NativeFlow(private val origin: Flow, private val scope: CoroutineScope) : Flow by origin {
    fun collect(block: (T) -> Unit) = onEach { block(it) }.launchIn(scope)
    fun collectOnMain(block: (T) -> Unit) = onEach { block(it) }.launchIn(scope + Dispatchers.Main)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy