function fetchRowsFromRS(connection, resultSet, numRows) {
return resultSet
.getRows(numRows)
.then(function(rows) {
if (rows.length > 0) {
console.log('fetchRowsFromRS(): Got ' + rows.length + ' rows')
console.log(rows) //getting data here
if (rows.length === numRows)
// might be more rows
fetchRowsFromRS(connection, resultSet, numRows)
else doClose(connection, resultSet) // always close the ResultSet
} else {
// no rows
doClose(connection, resultSet) // always close the ResultSet
}
return rows
})
.catch(function(err) {
if (err) {
console.error(err)
doClose(connection, resultSet) // always close the ResultSet
}
})
}
Вышеприведенное сработает, если resultSet.getRows (numRows) возвращает обещание вместо принятия обратного вызова или есть альтернатива для resultSet.getRows (numRows) , которая возвращает обещаю.
await fetchRowsFromRS (соединение, набор результатов, numRows)
будет работать, только если fetchRowsFromRS (connection, resultSet, numRows) возвращает обещание, что, в свою очередь, требует, чтобы все, что определено внутри функции, возвращало обещание.
OR
Использовать Новое обещание
function fetchRowsFromRS(connection, resultSet, numRows) {
return new Promise(function(resolve, reject) {
resultSet.getRows(numRows, function(err, rows) {
if (err) {
console.error(err)
doClose(connection, resultSet) // always close the ResultSet
reject(err)
} else if (rows.length > 0) {
console.log('fetchRowsFromRS(): Got ' + rows.length + ' rows')
console.log(rows) //getting data here
if (rows.length === numRows)
// might be more rows
fetchRowsFromRS(connection, resultSet, numRows)
else doClose(connection, resultSet) // always close the ResultSet
} else {
// no rows
doClose(connection, resultSet) // always close the ResultSet
}
resolve(rows)
})
})
}