broken-promises | Broken Promises Examples | Machine Learning library
kandi X-RAY | broken-promises Summary
kandi X-RAY | broken-promises Summary
James M Snell / @jasnell. NearForm Head of Research.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of broken-promises
broken-promises Key Features
broken-promises Examples and Code Snippets
Community Discussions
Trending Discussions on broken-promises
QUESTION
A few days ago, I watched an interesting video on YouTube about Broken Promises that James Snell introduced.
You can find out some great examples that have introduced in the video from his repository.
According to what he said, we should not wrap purely synchronous code in a promise. And if we absolutely need a function to return a promise then resolve the promise synchronously by using
Promise.resolve() method
. Importantly, he also pointed out that run your code synchronously and save yourself the trouble of all those additional promise allocations.
After finished watching the video, I've looked into my code. And wonder what if I've done something similar as he mentioned in the clip.
Let me show you some examples.
Here's an async function that waits for promises to be resolved.
...ANSWER
Answered 2020-Jan-02 at 01:45None of the functions in your code are doing anything asynchronous. Once the await somefunc
line runs, everything else you're doing is synchronous, but you're still wrapping everything in a Promise.all
call for some reason. You can fix that (and avoid the antipattern the video discusses) by removing the unnecessary Promise constructions and Promise.resolve
s:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install broken-promises
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page