-
-
Save dfreudenberger/d70d315b0e78ded9341575a07bc59ae9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun getProducts(...): ReceiveChannel<ResultPage<Product>> = GlobalScope.produce { | |
var requestUrl: String? = "/api/rest/v1/products" | |
var firstRequest = true | |
do { | |
val response = httpClient.get<ResultPage<Product>> { | |
url(requestUrl!!) | |
header("Authorization", "Bearer ${token.accessToken}") | |
if (firstRequest) { | |
contentType(ContentType.Application.Json) | |
parameter("search", objectMapper.writeValueAsString(search)) | |
params.forEach { k, v -> parameter(k, v) } | |
firstRequest = false | |
} | |
} | |
send(response) | |
requestUrl = response.links.next?.href | |
} while (requestUrl != null) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment