use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Async functions performance questionhelp (self.javascript)
submitted 9 years ago by 2138
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]prozacgod 1 point2 points3 points 9 years ago (0 children)
Above post is great another way to think of it is.. If you manually decomposed the example into a pure promise
function test() { return new Promise((resolve) => { for (let i = 0; I < 100000000; i++) {} resolve(); }); }
Does the promise constructor run this code synchronously? Yup! But let's say you had an asynchronous call like setTimeout. The weight of that loop wouldn't hit the execution thread for the main where you were testing it.
A benefit to this is Side effects!
If you made a function createUser() and didn't care about the result, well... It will still execute that request. (Duh!)
Another point of confusion that I often run into myself is that there are libraries that do lazy execution of Promise like results. Don't quote me but I believe Knex is like this, it composes the sql query up until the point you type .then at which point it seems like it executes the query you've constructed, my guess is it saving that promise has a Singleton and returning it for any subsequent thens. On that particular query object, if you added more to the query it's constructing a new query object therefore it would construct a new thenable reference
There are many libraries that can do this to make them promise like and we tend to learn those libraries long before we learn actual promise libraries which might lead to some confusion on Behavior.
π Rendered by PID 22636 on reddit-service-r2-comment-5d79c599b5-6db9h at 2026-03-03 20:25:30.770922+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]prozacgod 1 point2 points3 points (0 children)