java - 如何等待 ComputerVision getReadResult 或 getReadResultAsync 方法完成?
问题描述
如何等待 getReadResultAsync 方法返回的 Observable 完成?或者确保 getReadResult() 返回完整的结果,而不在 while 循环中检查状态。
包裹:com.microsoft.azure.cognitiveservices.vision.computervision.ComputerVision;
readResults = computerVission.getReadResult(operationId);
While循环检查:
数量
ReadOperationResult readResults = null;
boolean pollForResult = true;
while (pollForResult) {
readResults = computerVission.getReadResult(operationId);
if (readResults != null) {
OperationStatusCodes status = readResults.status();
if (status == OperationStatusCodes.FAILED || status == OperationStatusCodes.SUCCEEDED) {
pollForResult = false;
}
}
}
解决方案
确保 getReadResult() 返回完整的结果,而不在 while 循环中检查状态。您可以尝试使用以下代码:
ReadOperationResult readResults = null;
boolean pollForResult = true;
if(readResults != null){
return readResults;
}
else{
OperationStatusCodes status = readResults.status();
if (status == OperationStatusCodes.FAILED|| status == OperationStatusCodes.SUCCEEDED) {
pollForResult = false;
}}
推荐阅读
- python - strptime 无法解析时区值 +02:00
- reactjs - 在 ReactJS 的组件构造方法中获取上下文值的任何方法
- ios - 允许使用 WKWebView 自签名证书
- nginx - 如何在 Nginx 上本地设置多个项目?
- fastq - 使用 fastq-dump 转换一堆或 SRA 文件
- node.js - 我想在 FeathersJS 的服务类构造函数中使用从自定义中间件获取的值
- c# - Xaml 的 CommandParameter="{Binding .}" 的 C# 等效项
- pointers - golang nil 指针赋值,忽略输出 - (*)(nil)
- java - 获取所有部署的 Kubernetes Client-Java API 是什么
- java - Json Java 中的枚举列表