You might have to wait a day, but <@U0H8MJ868> wil...
# squarelibraries
j
You might have to wait a day, but @alec will know
k
This is quickly hacked together but something like this would be nice to have.
Copy code
@ExperimentalCoroutinesApi
fun <T : Any> QueryDataSourceFactory<T>.asFlow(pageSize: Int): Flow<PagedList<T>> = flow {
    var dataSource: DataSource<Int, T> = this@asFlow.create()
    var invalidDataSource: DataSource<Int, T>? = null
    
    emit(PagedList.Builder(dataSource, pageSize).build())

    val channel = Channel<Unit>(Channel.CONFLATED)

    val callback = DataSource.InvalidatedCallback {
        invalidDataSource = dataSource
        dataSource = this@asFlow.create()
        channel.offer(Unit)
    }
    
    dataSource.addInvalidatedCallback(callback)
    
    try {
        channel.consumeEach {
            invalidDataSource?.removeInvalidatedCallback(callback)
            emit(PagedList.Builder(dataSource, pageSize).build())
            dataSource.addInvalidatedCallback(callback)
        }
    } finally {
        dataSource.removeInvalidatedCallback(callback)
    }
}
a
these are all android paging lib questions, not sqldelight - we just make the data source factory and from there its all paging apis