alexhelder
04/10/2025, 10:01 PMitems
to not block the thread:
• daggerLazyPagerFactory
is dagger.Lazy, get()
bocks the thread in my case
• i have the flow { }
builder just with a single emitAll
, which seems wrong, but moves the blocking get()
to Dispatcher.Default
val items: Flow<PagingData<Item>> = flow {
emitAll(daggerLazyPagerFactory.get().flow())
}.flowOn(Dispatchers.Default)
.cachedIn(viewModelScope)
If I try this, get() blocks the thread, as flowOn{}
does not impact that:
val items = daggerLayPagerFactory.get()
.flow()
.flowOn(Dispatchers.Default)
.cacheIn(...)
Robert Williams
04/11/2025, 9:32 AMRobert Williams
04/11/2025, 9:32 AMRobert Williams
04/11/2025, 9:50 AMflow {
val pager = withContext(Dispatchers.Default) {
daggerLazyPagerFactory.get()
}
emitAll(pager.flow())
}
And then you won't need flowOn
alexhelder
04/11/2025, 1:55 PMwithContext
in flow{ }
builder as long as you don’t emit anything in its block, I though this violated the context preservation policy. Also thanks for the heads up about dreaded suspend funs returning flows, if its a bad I idea I will come up with it eventually 😆