I’m starting to learn asynchronous Javascript and I’m really confused. To be honest, the async/await approach seems very logical to me. We need to let the runtime know we’re doing an asynchronous operation so it can handle it accordingly. But why don’t we need to do the same when using the .then() method? I mean, if Javascript was already able
Tag: es6-promise
Javascript Promises catch block not working?
I am trying to make a function that calls promises synchronously so that if any of them return false the execution stops and returns the reject object with the reason why the promise returned false. Right now I am getting the error: UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by
Trying to retrieve information from a db [node js, mysql, promise]
This is supposed to be a simple connection to access a localhost database. Important information: I’ve tried very similar code, if not the exact same, and it works. The difference is I didn’t put the connection in a class variable (this.connection) but because it’s not async I didn’t think much of it. So maybe it’s simply a just javascript syntax
Is Observables is also executed in the same way like promises in the call stack? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago. Improve this question I’m a complete novice when it comes to Javascript. Please assist me in comprehending the concepts of Observables. Do Observables
Javascript Promises are not executed in the correct order
I have a problem. I am trying to do the following: I first check the url for a containing agentId parameter. Then I want to check in my database if the given agentId belongs to a valid agent. If so, then I want to store the entire object of that agent in a variable called selectedAgent. Then I want to
Throwing errors in async await functions and catching from where it’s called
How can we catch error from an async await function from where it’s called? For example, I have a React component which calls a async-await function imported from another module. When I use Promise.reject(“An unknown has occurred”); in that function, so in my React component why can’t I get the error in asyncAwaitFunction.catch((e)=>console.log(e))? I even tried throw “An unknown occured”,
How to make React Redux async action return a promise?
I have a redux action function that returns a promise. Inside that function body, there is another async function that returns a callback when it finished the call. Then I call this function in another place chaining it with .then() but when debugging it in the browser with breakpoints, the promise function exists after the first two lines of code
Alternative for Promise.allSettled
I am currently using Promise.allSettled to wait for all my promises to finish(irrespective of whether they resolve or get rejected). Since my project is compliant to Node v12.3.1 I am unable to use this? What other simple alternatives can I use. Sample code: Note: Promise.allSettled is available from Node version >12.9. Adding shims is also not an option. Answer There’s
when I learned about microtask and Promise , I came across a behavior I don’t understand
I didn’t return something in then() callback, In my opinion the output should be 1 5 7 2 6 3 4,but the result is 1 2 5 3 6 7 4, who can tell me why Answer Alright, this will be very verbose. Contrary to others, i’ll claim, that the execution order for the console.log calls is completely deterministic here.
How to return a promise resolved from a callback
I have an issue with my promise logic (still pretty new to JS), and I cannot find what is wrong. Looking at how hard it is for me to do what I want, I can only guess that’s it’s not the correct way to do it. I did found another way to fix it, but I am still interested if