有没有办法通过 while 循环内 api 的 Mono.fromCallable() 返回值来更新局部变量?
我需要多次运行 GET 请求,直到 GET 返回空数组为止。 目前,我一直在使用全局 receiveAllApiData 变量来完成此操作,如果它是空数组,我会在 getApiValues 中更新它。但是我需要找到一种方法在本地方法中执行此操作。有没有办法 mono.fromCallable 可以更改局部变量?
while (!receivedAllApiData && offsetAmount < MAX_REQUEST_FALLBACK) {
int offset = offset;
Mono.fromCallable(() -> Api.getApiValues(Id, offset, LIMIT, property))
.map(this::getApiValues)
.subscribe(this::buildStructure, this::ErrorCounter);
offsetAmount += LIMIT;
}
也许有更好的方法来运行多个调用?
I need to run GET requests multiple times until the return of the GET is an empty array.
Currently I have been doing it with a global receivedAllApiData variable I update in getApiValues if it is an empty array. However I need to find a way to do this in the method locally. Is there a way the mono.fromCallable could change a local variable?
while (!receivedAllApiData && offsetAmount < MAX_REQUEST_FALLBACK) {
int offset = offset;
Mono.fromCallable(() -> Api.getApiValues(Id, offset, LIMIT, property))
.map(this::getApiValues)
.subscribe(this::buildStructure, this::ErrorCounter);
offsetAmount += LIMIT;
}
maybe there is a better way to run several calls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用atomicBoolean,您可以更新映射函数内的值,如下所示。
Using an atomicBoolean you can update the value inside the map function as below.