promise

How to promisify Mongo/Mongoose find

不问归期 提交于 2020-06-01 05:07:46
问题 As part of another question I am trying to promisify a mongo/mongoose find query. I found little help via the search bar. The query is below, I am running this query as part of a controller in express. Setup is route -> userController.monitor which needs to contain the query In getting help for the other question I was asked to promisify find so that you can use await for it (like const incidents = Incident.find({fooID}).exec(); though SO search and my attempts at promisifying it myself have

How to promisify Mongo/Mongoose find

与世无争的帅哥 提交于 2020-06-01 05:06:07
问题 As part of another question I am trying to promisify a mongo/mongoose find query. I found little help via the search bar. The query is below, I am running this query as part of a controller in express. Setup is route -> userController.monitor which needs to contain the query In getting help for the other question I was asked to promisify find so that you can use await for it (like const incidents = Incident.find({fooID}).exec(); though SO search and my attempts at promisifying it myself have

javascript async await Submitting a form with onsubmit using Promise

梦想的初衷 提交于 2020-05-30 03:22:26
问题 I'm having following code. <!DOCTYPE html> <html> <head> <script type="text/javascript"> function sleep( lf_ms ) { return new Promise( resolve => setTimeout( resolve, lf_ms ) ); } async function check_form() { alert( 'Test 1' ); await sleep( 1000 ); alert( 'Test 2' ); return false; } </script> </head> <body> <form name="myform" method="post" action="test.htm" onsubmit="return check_form();"> <input type="text" name="city"><br> <br> <a href="javascript:check_form();">check the method call via

Can I get the future unhandled promise rejection behaviour now?

只愿长相守 提交于 2020-05-29 22:53:08
问题 In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. My pipeline passed when it should have failed and deployed a version that is crashing on launch. If Node.js would have exited with a non-zero exit code, the pipeline would have failed and the bad version wouldn't have been deployed. Is there a way to make Node.js exit with a non-zero exit code when it encounters an unhandled promise rejection, that doesn't require me to wait

Can I get the future unhandled promise rejection behaviour now?

寵の児 提交于 2020-05-29 22:46:13
问题 In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. My pipeline passed when it should have failed and deployed a version that is crashing on launch. If Node.js would have exited with a non-zero exit code, the pipeline would have failed and the bad version wouldn't have been deployed. Is there a way to make Node.js exit with a non-zero exit code when it encounters an unhandled promise rejection, that doesn't require me to wait

How to return a Promise with setInterval()

陌路散爱 提交于 2020-05-28 11:51:09
问题 I am trying to return a Promise object ever 1000ms, but i am not sure how to access the data returned in the Promise when it is inside a setInterval() callback. EDIT I appears i was not being very clear as to my intentions, so i will try and explain what it is i am trying to do. I making a count down where by the necessary calculations are are don every 1000ms based on specified end date. Here is the code that provides the return value i would like returned as a Pormise value every 1000ms:

Node js promise inside for loop always prints Promise { <pending> }

自闭症网瘾萝莉.ら 提交于 2020-05-24 06:10:11
问题 I'm trying to resolve a promise inside a for-loop in node js. In my code, I have a for loop in which I call a function findincollection that returns a promise. Then I push the data to finalresult array and resolve it once the for loop completes. But the issue I'm facing is it doesn't resolve the complete data. The for loop execution is getting finished before all the promises are resolved. The line console.log(p1); always prints Promise { } but it eventually gets resolved as you can see in my

dealing with an array of objects with promises

与世无争的帅哥 提交于 2020-05-24 03:51:47
问题 I am trying to make a node express app where I fetch data from different url's making a call to node-fetch to pull the body of some pages and other information about certain url endpoints. I want to then render a html table to display this data through an array of information. I am having trouble with the call to render the information as all the functions are asynchronous making it difficult to make sure all the promise calls have been resolved before making my call to render the page. I

How JavaScript promises work behind the scenes

丶灬走出姿态 提交于 2020-05-22 03:52:46
问题 I'm so much confused about what happens behind the scenes when promise is produced and consume. Please clarify my points and sorry for my weak English. blank object is created with new keyword Promise constructor is called and new keyword set the this of Promise constructor points to the blank object this = blankobject. Promise constructor receives callback (executor function) in argument and calls the executor function. executor function receives two callbacks (resolve,reject) as arguments

How JavaScript promises work behind the scenes

余生颓废 提交于 2020-05-22 03:49:08
问题 I'm so much confused about what happens behind the scenes when promise is produced and consume. Please clarify my points and sorry for my weak English. blank object is created with new keyword Promise constructor is called and new keyword set the this of Promise constructor points to the blank object this = blankobject. Promise constructor receives callback (executor function) in argument and calls the executor function. executor function receives two callbacks (resolve,reject) as arguments