in quick-start/typescript/RedshiftDataAPI.js [160:207]
var executeSynchronousWait = function (redshiftDataApiClient, queryStatus, queryId, command) { return __awaiter(void 0, void 0, void 0, function () {
var attempts, MAX_WAIT_CYCLES, describeStatementResult, descStatError, descStateHasResultSet;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
attempts = 0;
MAX_WAIT_CYCLES = 20;
_a.label = 1;
case 1:
if (!(attempts < MAX_WAIT_CYCLES)) return [3 /*break*/, 9];
attempts++;
return [4 /*yield*/, sleep(1)];
case 2:
_a.sent();
return [4 /*yield*/, getDescribeStatement(redshiftDataApiClient, queryId)];
case 3:
describeStatementResult = _a.sent();
descStatError = describeStatementResult.Error, descStateHasResultSet = describeStatementResult.HasResultSet;
(queryStatus = describeStatementResult.Status);
if (!(queryStatus === 'FAILED')) return [3 /*break*/, 4];
throw new Error("SQL query failed: " + queryId + ": \n Error: " + descStatError);
case 4:
if (!(queryStatus === 'FINISHED')) return [3 /*break*/, 7];
console.log("Query status is: " + queryStatus + " for query id: " + queryId + " and command: " + command);
if (!descStateHasResultSet) return [3 /*break*/, 6];
return [4 /*yield*/, redshiftDataApiClient.getStatementResult({ Id: queryId }).promise()
.then(function (statementResult) {
console.log("Printing response for query: " + command + " --> " + JSON.stringify(statementResult.Records));
})["catch"](function (error) {
console.log('GetStatementResult has failed.');
throw new Error(error.message);
})];
case 5:
_a.sent();
_a.label = 6;
case 6: return [3 /*break*/, 9];
case 7:
console.log("Currently working... query status is " + queryStatus);
_a.label = 8;
case 8:
if (attempts >= MAX_WAIT_CYCLES) {
throw new Error("Limit for MAX_WAIT_CYCLES has been reached before the query was able to finish. We have exited out of the while-loop. You may increase the limit accordingly. \n Query status is: %s for query id: " + queryId + " and command: " + command);
}
return [3 /*break*/, 1];
case 9: return [2 /*return*/, queryStatus];
}
});
}); };