App hang when using promises/async on connecting
See original GitHub issueI’m using NodeJS 8.11.3
with Monk 6.0.6
and I have the next piece of code:
function monkConnect(url) {
return new Promise(resolve => {
resolve(monk(url));
});
}
await monkConnect("some valid url");
I have tried in so many ways to make this works( using the callback from monk(url)
, making the function async
and calling await
on monk, and so many methods) and the code just freeze/hang and nothing happen and I don’t know how to resolve it. Please some help.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6
Top Results From Across the Web
Use Promise.all to Stop Async/Await from Blocking Execution ...
Use Promise.all to Stop Async/Await from Blocking Execution in JS. When writing asynchronous code, async/await is a powerful tool — but it comes...
Read more >usage of promise with while loop results in freezing ui
When I attempt to execute new version of the code using promise browsers freezes and seems to be executing infinite loop. Could you...
Read more >Breaking Ui Code Into Async Blocks And Avoid Freezing Ui
This is a technical article on how Acousterr's tab parser utilizes Javascript Promises to avoid freezing UI while parsing is in progress. Background...
Read more >How to use promises - Learn web development | MDN
With a promise-based API, the asynchronous function starts the operation and returns a Promise object. You can then attach handlers to this ...
Read more >Changing Async/Await to Promises.allSettled() to Speed Up ...
And since it iterates over the records and updates them one by one, the time goes up linearly as there are more records...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A year later, this is still a problem, and I don’t think there’s a solution that doesn’t break compatibility.
The only workaround I’ve been able to use is:
Essentially, remove the
then
to avoid JS treating it as athen
-able (which will cause it to never resolve, because it resolves to itself in a loop forever), then constructing my own promise.I ran into this problem yesterday as well and have tried all manner of things. I’m not sure if the
monk
constructor is returning a proper promise. It sets up a bunch of functions on it including athen
function:However, if mongo isn’t actually running when
monk
tries to connect, it doesn’t use the reject function passed into the then function above, it just breaks out and I get an unhandled promise rejection error.It would be great if this problem could get fixed, because I’m trying to use
async/await
to wait until monk connects before trying to get some data out of the database, but that’s not possible currently.