dave08
11/14/2023, 9:46 AMparRun { }
in the Raise
context for something similar to what parZip
does, that might be a pretty powerful idea... one could always use async { }
from coroutines, but the handling of errors and bypassing things could maybe be simplified with parRun { }
...simon.vergauwen
11/14/2023, 2:36 PMparRun
do in this case? 🤔dave08
11/14/2023, 2:38 PMsimon.vergauwen
11/14/2023, 2:48 PMdave08
11/14/2023, 2:50 PMfun getHomeScreenContent() = either {
val groups = api.getGroups(..).bind()
groups.map {
parRun { api.getGroupContent(it.id).bind() }
}
}
fun getItemDetails() = either {
val summary = parRun { api.getItemSummary(..).bind() }
val details =
parRun { api.getItemDetails(...).bind() }
Item(summary, details)
}
fun getItemDetails() = either {
val summary = parRun { api.getItemSummary(..).bind() }
val details = if (summary...)
parRun { api.getItemDetails(...).bind() }
else
...
Item(summary, details)
}
simon.vergauwen
11/14/2023, 2:56 PMdetails
and summary
run in parallel here if they immediately return the value so that's.
fun getItemDetails() = either {
parZip(
{ api.getItemSummary(..).bind() },
{ api.getItemDetails(...).bind() }
) { summary, details -> Item(summary, details) }
}
The other snippet:
fun getHomeScreenContent() = either {
val groups = api.getGroups(..).bind()
groups.parMap {
api.getGroupContent(it.id).bind()
}
}
dave08
11/14/2023, 2:58 PMfun getItemDetails() = either {
val summary = parRun { api.getItemSummary(..).bind() }
val details =
parRun { api.getItemDetails(...).bind() }
awaitParRun()
Item(summary, details)
}
simon.vergauwen
11/14/2023, 2:58 PMsummary
and details
? It would need to be something like Deferred
dave08
11/14/2023, 2:59 PMfun getItemDetails() = either {
val summary = parRun { api.getItemSummary(..).bind() }
val details =
parRun { api.getItemDetails(...).bind() }
Item(summary.bind(), details.bind())
}
where the binds on the parRun await their resultsawaitParRun()
and Arrow users are already used the notion of bind()
to get results..bind()
on Deferred
@simon.vergauwen? What do you think of the whole idea?