com.reown.foundation.network.data.adapter.FlowStreamAdapter.kt Maven / Gradle / Ivy
The newest version!
package com.reown.foundation.network.data.adapter
import com.tinder.scarlet.Stream
import com.tinder.scarlet.StreamAdapter
import com.tinder.scarlet.utils.getRawType
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.reactive.collect
import java.lang.reflect.Type
class FlowStreamAdapter : StreamAdapter> {
override fun adapt(stream: Stream) = flow {
stream.collect {
emit(it)
}
}
class Factory : StreamAdapter.Factory {
override fun create(type: Type): StreamAdapter {
return when (type.getRawType()) {
Flow::class.java -> FlowStreamAdapter()
else -> throw IllegalArgumentException()
}
}
}
}