package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.* fun aggregateFlows( withScope: CoroutineScope, vararg flows: Flow, internalBufferSize: Int = Channel.BUFFERED ): Flow { val bc = BroadcastChannel(internalBufferSize) flows.forEach { it.onEach { safely { bc.send(it) } }.launchIn(withScope) } return bc.asFlow() }