首页 > 解决方案 > 如何等待 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;
                }
            }
}

标签: javaazurerx-java

解决方案


确保 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;
            }}

推荐阅读