commonMain.com.lt.lazy_people_http.call.adapter.FlowCallAdapter.kt Maven / Gradle / Ivy
package com.lt.lazy_people_http.call.adapter
import com.lt.lazy_people_http.call.CallCreator
import com.lt.lazy_people_http.config.LazyPeopleHttpConfig
import com.lt.lazy_people_http.request.RequestInfo
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
/**
* creator: lt 2023/6/28 [email protected]
* effect : 构造[Flow]类型的返回值对象
* warning:
*/
class FlowCallAdapter : CallAdapter> {
override fun canItAdapt(
config: LazyPeopleHttpConfig,
info: RequestInfo,
returnTypeName: String
): Boolean {
return "kotlinx.coroutines.flow.Flow" == returnTypeName
}
override fun adapt(config: LazyPeopleHttpConfig, info: RequestInfo): Flow<*> {
return flow {
try {
emit(
CallCreator.createCall(config, info).await()
)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}