diff options
author | Allan Wang <me@allanwang.ca> | 2021-11-23 18:29:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 18:29:05 -0800 |
commit | 120ad1520db9184ebfa00885066e06a9f976e5f6 (patch) | |
tree | 50835fa79cf15ff348be386c46cea0a05552ba74 /app/src/main/kotlin/com/pitchedapps/frost/kotlin/CoroutineUtils.kt | |
parent | e246b35323e27dd18fa48910e5ca95669b53f8b0 (diff) | |
parent | db646e23ce0047461e68be1af7021ce6171ac850 (diff) | |
download | frost-120ad1520db9184ebfa00885066e06a9f976e5f6.tar.gz frost-120ad1520db9184ebfa00885066e06a9f976e5f6.tar.bz2 frost-120ad1520db9184ebfa00885066e06a9f976e5f6.zip |
Merge pull request #1857 from AllanWang/flows
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/kotlin/CoroutineUtils.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/kotlin/CoroutineUtils.kt | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/kotlin/CoroutineUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/kotlin/CoroutineUtils.kt deleted file mode 100644 index 6f8a60a9..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/kotlin/CoroutineUtils.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2019 Allan Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package com.pitchedapps.frost.kotlin - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.Job -import kotlinx.coroutines.channels.BroadcastChannel -import kotlinx.coroutines.launch -import kotlin.coroutines.CoroutineContext - -@UseExperimental(ExperimentalCoroutinesApi::class) -fun <T> BroadcastChannel<T>.subscribeDuringJob( - scope: CoroutineScope, - context: CoroutineContext, - onReceive: suspend (T) -> Unit -) { - val receiver = openSubscription() - scope.launch(context) { - for (r in receiver) { - onReceive(r) - } - } - scope.coroutineContext[Job]!!.invokeOnCompletion { receiver.cancel() } -} |