I am just starting to work with JS and SQLite. And could not find any help for my specific question. I want to keep a return to use it as a foreign key in a second table. This is my function: What do I have to do so that promise does not stay undefined outside of the function? Rest of the code: My other function just creat some strings and I run a few times db.run(…) to add some tables. Answer To put it more plainly, your getIdByName function never returns anything. You need to return the value you get
I’m trying to perform async function and then console log the results with the help of Promise. I’m afraid I haven’t quite grasped the concept yet. I wanted to wait till getlinks finished performing tasks and then console log the result. But the it logs the result as empty even before the getlink is finished. Answer The simplest answer is you’re promise is resolving (return resolve(utlUrls)) before your async code (axios.get(…).then(…)) completes. This is a minimal example to reproduce your problem: It doesn’t work because we return ultUrls before we’ve filled it. We don’t wait for the timeouts to complete.
my data which is fetched from youtube is using nodejs is – Now I want to search 5 related videos to each video my api and api to 5 related Videos is given below It is giving the output like How to solve this pending problem or how to wait so it gets full data. Answer It happens because you assign the promise returned by relatedVideos() to the property relatedVideos, you never actually wait for it to resolve. You need to await all of the promises before you proceed, this is most easily done with Promise.all(). Let’s focus on this
I found out that running async-await can be much slower in some scenarios. IMO, the console.log in usingPromises should print similar results to the one in usingAwait. But in reality, I get: Total (promises): 0.25 ms Total (await): 2.065 ms Also, after the page load, if I click on ‘usingPromises’ or ‘usingAwait’ button I get similar results for each of them. (both are fast when running alone) Total (promises): 0.060000000026775524 ms Total (await): 0.08999999999650754 ms But if I click on the ‘both’ button, the ‘await’ version is ~3-4 times slower than the promises version. I have a real application running
Working with Nodejs and MongoDB through Node MongoDB native driver. Need to retrieve some documents, and make modification, then save them right back. This is an example: With asynchronous nature, if the process of updating the document takes longer, then when cursor reaches the end of documents, database connection is closed. Not all updates are saved to the database. If the db.close() is omitted, all the documents are correctly updated, but the application hangs, never exits. I saw a post suggesting using a counter to track number of updates, when fall back to zero, then close the db. But am