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 PMdave08
11/14/2023, 2:46 PMdave08
11/14/2023, 2:48 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() }
}
}dave08
11/14/2023, 2:53 PMfun getItemDetails() = either {
val summary = parRun { api.getItemSummary(..).bind() }
val details =
parRun { api.getItemDetails(...).bind() }
Item(summary, details)
}dave08
11/14/2023, 2:53 PMdave08
11/14/2023, 2:54 PMdave08
11/14/2023, 2:55 PMfun getItemDetails() = either {
val summary = parRun { api.getItemSummary(..).bind() }
val details = if (summary...)
parRun { api.getItemDetails(...).bind() }
else
...
Item(summary, details)
}dave08
11/14/2023, 2:55 PMsimon.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)
}dave08
11/14/2023, 2:58 PMsimon.vergauwen
11/14/2023, 2:58 PMsummary and details? It would need to be something like Deferreddave08
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 resultsdave08
11/14/2023, 3:01 PMawaitParRun() and Arrow users are already used the notion of bind() to get results..dave08
11/14/2023, 3:06 PMdave08
11/14/2023, 4:10 PMbind() on Deferred @simon.vergauwen? What do you think of the whole idea?dave08
11/14/2023, 4:22 PM