Retrofit2 why there is no CallAdapterFactory for Flow

Viewed 725

I consider why there is no Retrofit2 adapter for Flow type like FlowCallAdapter and FlowCallAdapterFactory?

I found that retrofit supports suspend functions, and http request are one-shot so it better fits to have suspend functions rather then Flow return type, but Flow is more equivalent of RxJava and reactive programming frameworks and better fit in this schema of programming

How I can do something like this withoud Retrofit returning Flow and instead having suspend function

      rules
        .filter { it.isAsync }
        .asFlow()
        .flatMapMerge {
            val rule = it
            rule.validateAsync(input)
                .filter { !it }
                .map { rule }
        }
        .scan(mutableListOf<String>()) { acc, rule ->
            acc.add(rule.errorMessage)
            acc
        }
        .flowOn(Dispatchers.IO)

If I am using suspend I need to do something like this generally

return flow { emit(service.validate(email = value)) }
1 Answers

Because HTTP does not return a sequence of responses, only one response at a time. They replied they are not going to support that https://github.com/square/retrofit/issues/3497 But you can implement your own CallAdapter to use flow

Related