Skip to content

Commit ec77f40

Browse files
优化ViewModel扩展函数
1 parent c57274f commit ec77f40

File tree

1 file changed

+3
-5
lines changed
  • lite/src/main/java/com/pengxh/kt/lite/extensions

1 file changed

+3
-5
lines changed

lite/src/main/java/com/pengxh/kt/lite/extensions/ViewModel.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ import kotlinx.coroutines.launch
1414
*/
1515
fun ViewModel.launch(
1616
block: suspend CoroutineScope.() -> Unit,
17-
onError: (e: Throwable) -> Unit = {},
17+
onError: (Throwable) -> Unit = {},
1818
onComplete: () -> Unit = {}
1919
) {
2020
viewModelScope.launch(
2121
CoroutineExceptionHandler { _, throwable ->
22-
run {
23-
onError(throwable)
24-
}
22+
onError(throwable)
2523
}
2624
) {
2725
try {
28-
block.invoke(this)
26+
block()
2927
} finally {
3028
onComplete()
3129
}

0 commit comments

Comments
 (0)