Skip to content

Commit

Permalink
chore: remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 8, 2023
1 parent 260d77f commit 19e9be4
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions app/src/main/java/li/songe/gkd/util/CoroutineExt.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package li.songe.gkd.util

import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.coroutineContext


fun CoroutineScope.launchWhile(
Expand All @@ -23,23 +21,6 @@ fun CoroutineScope.launchWhile(
}
}


fun CoroutineScope.launchWhileTry(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
interval: Long = 0,
block: suspend CoroutineScope.() -> Unit,
) = launch(context, start) {
while (isActive) {
try {
block()
} catch (e: Exception) {
e.printStackTrace()
}
delay(interval)
}
}

fun CoroutineScope.launchTry(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
Expand All @@ -51,6 +32,7 @@ fun CoroutineScope.launchTry(
e.printStackTrace()
} catch (e: Exception) {
e.printStackTrace()
LogUtils.d(e)
ToastUtils.showShort(e.message)
}
}
Expand Down Expand Up @@ -91,9 +73,3 @@ fun <T> CoroutineScope.launchAsFn(
}
}

suspend fun stopJob(): Nothing {
coroutineContext[Job]?.cancel()
delay(1)
error("stop failed")
}

0 comments on commit 19e9be4

Please sign in to comment.