Я использую асинхронное ожидание, и мое ожидание никогда не разрешается, поэтому следующая строка не выполняется вообще.Под этим я подразумеваю эту строку:
result = await IndexingStatusResult(req, res);
в следующем коде:
router.post(
"/api/result-store/v1/indexing-analyzer/:searchID/:id",
async (req, res) => {
console.log("Indexing started");
var hrstart = process.hrtime();
let result = null;
result = await IndexingStatusResult(req, res);
console.log("result is: ", result.data);
hrend = process.hrtime(hrstart);
console.info("Execution time (hr): %ds %dms", hrend[0], hrend[1] / 1000000);
res.status(200).send({
indexingTimeSec: hrend[0],
indexingTimeMillSec: hrend[1] / 1000000
});
}
);
Но, как вы видите в IndexingStatusResult, я возвращаю обещание, когда все сделано:
const IndexingStatusResult = async (req, res) => {
const docID = parseInt(req.params.id) * 1000;
const dbName = "test_" + req.params.searchID;
let result = null;
try {
result = await axios(
`${params.HOST_NAME_WITH_PROTOCOL}/${dbName}/_design/searchAll/_search_info/searchAll`
);
result = result.data;
console.log(
"Number of docs indexed:",
result.search_index.doc_count,
"Total Docs needs to be indexed:",
docID
);
} catch (e) {
console.log(e);
}
console.log(`result returned is : ${JSON.stringify(result)}`);
if (!result || parseInt(result.search_index.doc_count) < docID) {
return Promise.resolve(
setTimeout(() => {
console.log("WWWWWAAAAIIIIIITING");
IndexingStatusResult(req, res);
}, 5000)
);
} else {
console.log("YAAAAAAYYYYYYYYYYYYY");
return Promise.resolve(result);
}
};
Вот что я вижу:
Example app listening on port 3005!
Indexing started
Number of docs indexed: 0 Total Docs needs to be indexed: 5000
result returned is : {"name":"_design/searchAll/searchAll","search_index":{"pending_seq":0,"doc_del_count":0,"doc_count":0,"disk_size":0,"committed_seq":0}}
result is: undefined
Execution time (hr): 0s 314.964402ms
WWWWWAAAAIIIIIITING
Number of docs indexed: 0 Total Docs needs to be indexed: 5000
result returned is : {"name":"_design/searchAll/searchAll","search_index":{"pending_seq":0,"doc_del_count":0,"doc_count":0,"disk_size":0,"committed_seq":0}}
WWWWWAAAAIIIIIITING
Number of docs indexed: 5001 Total Docs needs to be indexed: 5000
result returned is : {"name":"_design/searchAll/searchAll","search_index":{"pending_seq":5001,"doc_del_count":0,"doc_count":5001,"disk_size":797698,"committed_seq":0}}
YAAAAAAYYYYYYYYYYYYY
Таким образом, следующая строка никогда не выполняется:
console.log("result is: ", result.data);
Я что-то не так делаю?