getUpdateFlow

inline fun getUpdateFlow(timeout: Int? = null, firstOffset: Int? = null, eachLimit: Int? = null, allowedUpdates: Collection<String>? = null, crossinline onEachResult: (List<Update>) -> List<Update> = { it }, crossinline onError: suspend (Throwable) -> List<Update> = { if (it is HttpRequestTimeoutException) emptyList() else throw it }, crossinline requestor: suspend (GetUpdatesApi) -> List<Update>): Flow<Update>(source)

Create a Flow based on Long Polling with GetUpdatesApi.

getUpdateFlow(...) { api ->
httpClient.requestData(token, server)
}

Receiver

The HttpClient to call this long polling. It is recommended to configure a larger requestTimeoutMillis value, at least larger than the milliseconds value corresponding to timeout. Otherwise, an HttpRequestTimeoutException is likely to be thrown. (HttpRequestTimeoutException will be caught by default onError.

Parameters

eachLimit

see GetUpdatesApi.Body.limit. It is recommended to set a larger value, and its millis value should be smaller than the requestTimeoutMillis of the receiver client.

onEachResult

Handle each API result. Default: { it }: return itself.

onError

Handle exceptions during API requests. Default: { if (it is HttpRequestTimeoutException) emptyList() else throw it }: if it is HttpRequestTimeoutException, ignore. Otherwise, throw it.