reactormonk
10/16/2024, 3:43 PMemit
block?)
fun getSearchResultFlow(
api: SearchApi,
query: String,
pageSize: Int = 50
): Flow<Result> = flow {
var offset = 0
var hasMore = true
while (hasMore) {
val results = api.search(query, offset, pageSize)
results.forEach { emit(it) }
offset += pageSize
hasMore = results.size == pageSize
}
}
It's a small piece of code which iterates over a paginated list, so I can access as much as I need to.Sam
10/16/2024, 3:44 PMkevin.cianfarini
10/16/2024, 3:44 PMkevin.cianfarini
10/16/2024, 3:44 PMkevin.cianfarini
10/16/2024, 3:45 PMreactormonk
10/16/2024, 3:45 PMreactormonk
10/16/2024, 3:47 PMDmitry Khalanskiy [JB]
10/17/2024, 12:13 PMfrom Scala/Haskell, where blocking doesn't really existWell, that's a provocative take!
ScalaIt literally has a function called "blocking" (https://www.scala-lang.org/api/current/scala/concurrent.html#blocking-fffff7d2) to signify that this code is about to block and new threads need to be spawned.
HaskellThis feels closer to the truth, but still inaccurate when bound threads come into play: https://hackage.haskell.org/package/base-4.20.0.1/docs/Control-Concurrent.html#g:8
reactormonk
10/18/2024, 7:22 AM