Correct way of using Async/await in node.js
up vote
0
down vote
favorite
I have written some code to call a procedure,it's OUT parameter type is cursor(ResultSet),so i have to fetch data from ResultSet,for that i've written one function(fetchRowsFromRS()) which extract data from ResultSet.
- I've used return statement in fetchRowsFromRS(),but not returning
anything, getting undefined. - When i called fetchRowsFromRS(),control is not pausing execution
of next lines of code(i'have used Async/await) this is required because i want use extracted data in next lines.
What is the mistake in my code?
db.js
connection.execute(plsql,bindvars,options,async function (err, result) {
if (err) {
console.log(err);
console.error(err.message);
doRelease(connection);
return;
}
if(result.outBinds.OUT_STATUS=='SUCCESS'){
if(result.outBinds.OUT_MENU_NAME.metaData.length=0){
loginRes.getUserLoginServiceRes.Header.Status=aes.encryption('Failure');
loginRes.getUserLoginServiceRes.Header.Status_Desc=aes.encryption('No record found in database');
}else{
loginRes.getUserLoginServiceRes.Header.Status=aes.encryption('Success');
loginRes.getUserLoginServiceRes.Header.Status_Desc=aes.encryption('User
logged in successfully');
var numRows=20;
//calling function to fetch data from ResultSet
var rsData=await fetchRowsFromRS(connection,result.outBinds.OUT_MENU_NAME,numRows)
console.log('----------'+rsData);//giving undefined
//here i want to use ResultSet Data
}
}
})
function to extract data from ResultSet(not returning anything)
function fetchRowsFromRS(connection, resultSet, numRows) {
resultSet.getRows(numRows,function (err, rows) {
if (err) {
console.error(err);
doClose(connection, resultSet); // always close the ResultSet
} 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
}
return rows;
});
}
javascript node.js async-await
New contributor
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I have written some code to call a procedure,it's OUT parameter type is cursor(ResultSet),so i have to fetch data from ResultSet,for that i've written one function(fetchRowsFromRS()) which extract data from ResultSet.
- I've used return statement in fetchRowsFromRS(),but not returning
anything, getting undefined. - When i called fetchRowsFromRS(),control is not pausing execution
of next lines of code(i'have used Async/await) this is required because i want use extracted data in next lines.
What is the mistake in my code?
db.js
connection.execute(plsql,bindvars,options,async function (err, result) {
if (err) {
console.log(err);
console.error(err.message);
doRelease(connection);
return;
}
if(result.outBinds.OUT_STATUS=='SUCCESS'){
if(result.outBinds.OUT_MENU_NAME.metaData.length=0){
loginRes.getUserLoginServiceRes.Header.Status=aes.encryption('Failure');
loginRes.getUserLoginServiceRes.Header.Status_Desc=aes.encryption('No record found in database');
}else{
loginRes.getUserLoginServiceRes.Header.Status=aes.encryption('Success');
loginRes.getUserLoginServiceRes.Header.Status_Desc=aes.encryption('User
logged in successfully');
var numRows=20;
//calling function to fetch data from ResultSet
var rsData=await fetchRowsFromRS(connection,result.outBinds.OUT_MENU_NAME,numRows)
console.log('----------'+rsData);//giving undefined
//here i want to use ResultSet Data
}
}
})
function to extract data from ResultSet(not returning anything)
function fetchRowsFromRS(connection, resultSet, numRows) {
resultSet.getRows(numRows,function (err, rows) {
if (err) {
console.error(err);
doClose(connection, resultSet); // always close the ResultSet
} 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
}
return rows;
});
}
javascript node.js async-await
New contributor
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
"I've used return statement infetchRowsFromRS": no, you have not. You have areturnin a callback function, which is a different function.
– trincot
Nov 18 at 14:08
What isconnection.execute? Given that it takes a node-style callback, it doesn't appear to promise-aware. Do not pass anasync functionas a callback.
– Bergi
Nov 18 at 14:30
3
Possible duplicate of How to use async await function object in Javascript?
– NAVIN
Nov 18 at 14:56
There are so many examples and tutorials why don't you invest time learning basics of javascript. You didn't used async-await and just asking other to fix your problem.
– NAVIN
Nov 18 at 14:57
@NAVIN Sorry about that, I am in the learning process of understanding javascript and node.js
– viswanath
Nov 18 at 17:00
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have written some code to call a procedure,it's OUT parameter type is cursor(ResultSet),so i have to fetch data from ResultSet,for that i've written one function(fetchRowsFromRS()) which extract data from ResultSet.
- I've used return statement in fetchRowsFromRS(),but not returning
anything, getting undefined. - When i called fetchRowsFromRS(),control is not pausing execution
of next lines of code(i'have used Async/await) this is required because i want use extracted data in next lines.
What is the mistake in my code?
db.js
connection.execute(plsql,bindvars,options,async function (err, result) {
if (err) {
console.log(err);
console.error(err.message);
doRelease(connection);
return;
}
if(result.outBinds.OUT_STATUS=='SUCCESS'){
if(result.outBinds.OUT_MENU_NAME.metaData.length=0){
loginRes.getUserLoginServiceRes.Header.Status=aes.encryption('Failure');
loginRes.getUserLoginServiceRes.Header.Status_Desc=aes.encryption('No record found in database');
}else{
loginRes.getUserLoginServiceRes.Header.Status=aes.encryption('Success');
loginRes.getUserLoginServiceRes.Header.Status_Desc=aes.encryption('User
logged in successfully');
var numRows=20;
//calling function to fetch data from ResultSet
var rsData=await fetchRowsFromRS(connection,result.outBinds.OUT_MENU_NAME,numRows)
console.log('----------'+rsData);//giving undefined
//here i want to use ResultSet Data
}
}
})
function to extract data from ResultSet(not returning anything)
function fetchRowsFromRS(connection, resultSet, numRows) {
resultSet.getRows(numRows,function (err, rows) {
if (err) {
console.error(err);
doClose(connection, resultSet); // always close the ResultSet
} 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
}
return rows;
});
}
javascript node.js async-await
New contributor
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have written some code to call a procedure,it's OUT parameter type is cursor(ResultSet),so i have to fetch data from ResultSet,for that i've written one function(fetchRowsFromRS()) which extract data from ResultSet.
- I've used return statement in fetchRowsFromRS(),but not returning
anything, getting undefined. - When i called fetchRowsFromRS(),control is not pausing execution
of next lines of code(i'have used Async/await) this is required because i want use extracted data in next lines.
What is the mistake in my code?
db.js
connection.execute(plsql,bindvars,options,async function (err, result) {
if (err) {
console.log(err);
console.error(err.message);
doRelease(connection);
return;
}
if(result.outBinds.OUT_STATUS=='SUCCESS'){
if(result.outBinds.OUT_MENU_NAME.metaData.length=0){
loginRes.getUserLoginServiceRes.Header.Status=aes.encryption('Failure');
loginRes.getUserLoginServiceRes.Header.Status_Desc=aes.encryption('No record found in database');
}else{
loginRes.getUserLoginServiceRes.Header.Status=aes.encryption('Success');
loginRes.getUserLoginServiceRes.Header.Status_Desc=aes.encryption('User
logged in successfully');
var numRows=20;
//calling function to fetch data from ResultSet
var rsData=await fetchRowsFromRS(connection,result.outBinds.OUT_MENU_NAME,numRows)
console.log('----------'+rsData);//giving undefined
//here i want to use ResultSet Data
}
}
})
function to extract data from ResultSet(not returning anything)
function fetchRowsFromRS(connection, resultSet, numRows) {
resultSet.getRows(numRows,function (err, rows) {
if (err) {
console.error(err);
doClose(connection, resultSet); // always close the ResultSet
} 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
}
return rows;
});
}
javascript node.js async-await
javascript node.js async-await
New contributor
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 18 at 13:59
viswanath
83
83
New contributor
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
viswanath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
"I've used return statement infetchRowsFromRS": no, you have not. You have areturnin a callback function, which is a different function.
– trincot
Nov 18 at 14:08
What isconnection.execute? Given that it takes a node-style callback, it doesn't appear to promise-aware. Do not pass anasync functionas a callback.
– Bergi
Nov 18 at 14:30
3
Possible duplicate of How to use async await function object in Javascript?
– NAVIN
Nov 18 at 14:56
There are so many examples and tutorials why don't you invest time learning basics of javascript. You didn't used async-await and just asking other to fix your problem.
– NAVIN
Nov 18 at 14:57
@NAVIN Sorry about that, I am in the learning process of understanding javascript and node.js
– viswanath
Nov 18 at 17:00
add a comment |
"I've used return statement infetchRowsFromRS": no, you have not. You have areturnin a callback function, which is a different function.
– trincot
Nov 18 at 14:08
What isconnection.execute? Given that it takes a node-style callback, it doesn't appear to promise-aware. Do not pass anasync functionas a callback.
– Bergi
Nov 18 at 14:30
3
Possible duplicate of How to use async await function object in Javascript?
– NAVIN
Nov 18 at 14:56
There are so many examples and tutorials why don't you invest time learning basics of javascript. You didn't used async-await and just asking other to fix your problem.
– NAVIN
Nov 18 at 14:57
@NAVIN Sorry about that, I am in the learning process of understanding javascript and node.js
– viswanath
Nov 18 at 17:00
"I've used return statement in
fetchRowsFromRS": no, you have not. You have a return in a callback function, which is a different function.– trincot
Nov 18 at 14:08
"I've used return statement in
fetchRowsFromRS": no, you have not. You have a return in a callback function, which is a different function.– trincot
Nov 18 at 14:08
What is
connection.execute? Given that it takes a node-style callback, it doesn't appear to promise-aware. Do not pass an async function as a callback.– Bergi
Nov 18 at 14:30
What is
connection.execute? Given that it takes a node-style callback, it doesn't appear to promise-aware. Do not pass an async function as a callback.– Bergi
Nov 18 at 14:30
3
3
Possible duplicate of How to use async await function object in Javascript?
– NAVIN
Nov 18 at 14:56
Possible duplicate of How to use async await function object in Javascript?
– NAVIN
Nov 18 at 14:56
There are so many examples and tutorials why don't you invest time learning basics of javascript. You didn't used async-await and just asking other to fix your problem.
– NAVIN
Nov 18 at 14:57
There are so many examples and tutorials why don't you invest time learning basics of javascript. You didn't used async-await and just asking other to fix your problem.
– NAVIN
Nov 18 at 14:57
@NAVIN Sorry about that, I am in the learning process of understanding javascript and node.js
– viswanath
Nov 18 at 17:00
@NAVIN Sorry about that, I am in the learning process of understanding javascript and node.js
– viswanath
Nov 18 at 17:00
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
fetchRowsFromRS is not returning anything. You don't seem to be using async/await correctly. resultSet.getRows uses a callback. Change it to return a Promise or wrap it in a Promise and return that from fetchRowsFromRS. Then you'll be able to await it.
add a comment |
up vote
0
down vote
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
}
})
}
The above will work if, resultSet.getRows(numRows) returns a promise instead of accepting a callback or there is some alternate for resultSet.getRows(numRows) which return a promise.
await fetchRowsFromRS(connection, resultSet, numRows)
will work only if fetchRowsFromRS(connection, resultSet, numRows) returns a promise, which in turn requires everything defines inside the function to return a promise.
OR
Use new Promise
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)
})
})
}
Avoid thePromiseconstructor antipattern! And in your first snippet, make sure toreturnthe inner promises from thethencallback or they won't be awaited.
– Bergi
Nov 18 at 15:23
@Jeevan Thanks a lot! for you suggestion.I've used resultSet.getRows(numRows) it returns a promise.
– viswanath
Nov 19 at 10:24
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
fetchRowsFromRS is not returning anything. You don't seem to be using async/await correctly. resultSet.getRows uses a callback. Change it to return a Promise or wrap it in a Promise and return that from fetchRowsFromRS. Then you'll be able to await it.
add a comment |
up vote
0
down vote
fetchRowsFromRS is not returning anything. You don't seem to be using async/await correctly. resultSet.getRows uses a callback. Change it to return a Promise or wrap it in a Promise and return that from fetchRowsFromRS. Then you'll be able to await it.
add a comment |
up vote
0
down vote
up vote
0
down vote
fetchRowsFromRS is not returning anything. You don't seem to be using async/await correctly. resultSet.getRows uses a callback. Change it to return a Promise or wrap it in a Promise and return that from fetchRowsFromRS. Then you'll be able to await it.
fetchRowsFromRS is not returning anything. You don't seem to be using async/await correctly. resultSet.getRows uses a callback. Change it to return a Promise or wrap it in a Promise and return that from fetchRowsFromRS. Then you'll be able to await it.
answered Nov 18 at 14:07
Sergiu Paraschiv
8,47432741
8,47432741
add a comment |
add a comment |
up vote
0
down vote
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
}
})
}
The above will work if, resultSet.getRows(numRows) returns a promise instead of accepting a callback or there is some alternate for resultSet.getRows(numRows) which return a promise.
await fetchRowsFromRS(connection, resultSet, numRows)
will work only if fetchRowsFromRS(connection, resultSet, numRows) returns a promise, which in turn requires everything defines inside the function to return a promise.
OR
Use new Promise
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)
})
})
}
Avoid thePromiseconstructor antipattern! And in your first snippet, make sure toreturnthe inner promises from thethencallback or they won't be awaited.
– Bergi
Nov 18 at 15:23
@Jeevan Thanks a lot! for you suggestion.I've used resultSet.getRows(numRows) it returns a promise.
– viswanath
Nov 19 at 10:24
add a comment |
up vote
0
down vote
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
}
})
}
The above will work if, resultSet.getRows(numRows) returns a promise instead of accepting a callback or there is some alternate for resultSet.getRows(numRows) which return a promise.
await fetchRowsFromRS(connection, resultSet, numRows)
will work only if fetchRowsFromRS(connection, resultSet, numRows) returns a promise, which in turn requires everything defines inside the function to return a promise.
OR
Use new Promise
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)
})
})
}
Avoid thePromiseconstructor antipattern! And in your first snippet, make sure toreturnthe inner promises from thethencallback or they won't be awaited.
– Bergi
Nov 18 at 15:23
@Jeevan Thanks a lot! for you suggestion.I've used resultSet.getRows(numRows) it returns a promise.
– viswanath
Nov 19 at 10:24
add a comment |
up vote
0
down vote
up vote
0
down vote
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
}
})
}
The above will work if, resultSet.getRows(numRows) returns a promise instead of accepting a callback or there is some alternate for resultSet.getRows(numRows) which return a promise.
await fetchRowsFromRS(connection, resultSet, numRows)
will work only if fetchRowsFromRS(connection, resultSet, numRows) returns a promise, which in turn requires everything defines inside the function to return a promise.
OR
Use new Promise
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)
})
})
}
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
}
})
}
The above will work if, resultSet.getRows(numRows) returns a promise instead of accepting a callback or there is some alternate for resultSet.getRows(numRows) which return a promise.
await fetchRowsFromRS(connection, resultSet, numRows)
will work only if fetchRowsFromRS(connection, resultSet, numRows) returns a promise, which in turn requires everything defines inside the function to return a promise.
OR
Use new Promise
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)
})
})
}
answered Nov 18 at 15:12
Jeevan
1326
1326
Avoid thePromiseconstructor antipattern! And in your first snippet, make sure toreturnthe inner promises from thethencallback or they won't be awaited.
– Bergi
Nov 18 at 15:23
@Jeevan Thanks a lot! for you suggestion.I've used resultSet.getRows(numRows) it returns a promise.
– viswanath
Nov 19 at 10:24
add a comment |
Avoid thePromiseconstructor antipattern! And in your first snippet, make sure toreturnthe inner promises from thethencallback or they won't be awaited.
– Bergi
Nov 18 at 15:23
@Jeevan Thanks a lot! for you suggestion.I've used resultSet.getRows(numRows) it returns a promise.
– viswanath
Nov 19 at 10:24
Avoid the
Promise constructor antipattern! And in your first snippet, make sure to return the inner promises from the then callback or they won't be awaited.– Bergi
Nov 18 at 15:23
Avoid the
Promise constructor antipattern! And in your first snippet, make sure to return the inner promises from the then callback or they won't be awaited.– Bergi
Nov 18 at 15:23
@Jeevan Thanks a lot! for you suggestion.I've used resultSet.getRows(numRows) it returns a promise.
– viswanath
Nov 19 at 10:24
@Jeevan Thanks a lot! for you suggestion.I've used resultSet.getRows(numRows) it returns a promise.
– viswanath
Nov 19 at 10:24
add a comment |
viswanath is a new contributor. Be nice, and check out our Code of Conduct.
viswanath is a new contributor. Be nice, and check out our Code of Conduct.
viswanath is a new contributor. Be nice, and check out our Code of Conduct.
viswanath is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361690%2fcorrect-way-of-using-async-await-in-node-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"I've used return statement in
fetchRowsFromRS": no, you have not. You have areturnin a callback function, which is a different function.– trincot
Nov 18 at 14:08
What is
connection.execute? Given that it takes a node-style callback, it doesn't appear to promise-aware. Do not pass anasync functionas a callback.– Bergi
Nov 18 at 14:30
3
Possible duplicate of How to use async await function object in Javascript?
– NAVIN
Nov 18 at 14:56
There are so many examples and tutorials why don't you invest time learning basics of javascript. You didn't used async-await and just asking other to fix your problem.
– NAVIN
Nov 18 at 14:57
@NAVIN Sorry about that, I am in the learning process of understanding javascript and node.js
– viswanath
Nov 18 at 17:00