JP Sugarbroad
11/24/2024, 11:54 PM@Composable
fun <T> rememberAsyncSaveable(vararg keys: Any?, block: suspend CoroutineScope.() -> T): State<Result<T>?> {
val state = rememberSaveable(*keys) { mutableStateOf<Result<T>?>(null) }
if (state.value == null) {
LaunchedEffect(state) {
state.value = runCatching { block() }
}
}
return state
}
(Modulo probably needing a custom saver.)ephemient
11/25/2024, 12:00 AMremember(*keys) { flow { emit(block()) } }.collectAsState(null)
I thinkJP Sugarbroad
11/25/2024, 12:01 AMJP Sugarbroad
11/25/2024, 12:02 AMJP Sugarbroad
11/25/2024, 12:05 AMephemient
11/25/2024, 12:08 AM.catch {}
them to ignore) but ok, if the savable part is important to you…JP Sugarbroad
11/25/2024, 12:10 AMJP Sugarbroad
11/25/2024, 12:11 AMephemient
11/25/2024, 12:13 AMJP Sugarbroad
11/25/2024, 12:14 AMJP Sugarbroad
11/25/2024, 12:14 AM