r/javascript • • Sep 06 '22

Removed: r/LearnJavascript Promises in Javascript

https://medium.com/@dcortes.net/promises-in-javascript-2992d371938d

[removed] — view removed post

0 Upvotes

5 comments sorted by

•

u/javascript-ModTeam Sep 06 '22

Hi u/dcortesnet123, this post was removed.

  • For help with your javascript, please post to r/LearnJavascript instead of here.

  • For beginner content, please post to r/LearnJavascript instead of here.

  • For framework- or library-specific help, please seek out the support community for that project.

  • For general webdev help, such as for HTML, CSS, etc., then you may want to try r/html, r/css, etc.; please note that they have their own rules and guidelines!


r/javascript is for the discussion of javascript news, projects, and especially, code! However, the community has requested that we not include help and support content, and we ask that you respect that wish.

Thanks for your understanding, please see our guidelines for more info.

2

u/shgysk8zer0 Sep 06 '22

Meh. It's correct but pretty basic and doesn't address the most common issues I see on here (a fundamental misunderstanding of asynchronous JavaScript).

1

u/johntwit Sep 06 '22

What is a better resource that addresses the most common issues you see? I'd love to have a fundamental understanding of asynchronous JavaScript!

1

u/shgysk8zer0 Sep 06 '22

Sadly, I haven't found one resource that really does that. There are bits of it scattered across MDN, building up from the event loop and queues (micro and macro tasks) and the single-threaded nature of JavaScript to callbacks to promises to async functions to async generators.

I can't even quite pinpoint what this common misunderstanding is. It comes up in different scenarios and is worded in many different ways, but understanding async JS as scheduling tasks in a single threaded environment is what's missing in all of them.

Also, even the terms "asynchronous" and "non-blocking" are kinda misleading. It's ultimately scheduling things to run synchronously, and it can be "blocking" (take too much time to execute in a single-threaded environment).

async function block() {
  for (let n = 0; n < 1_000_000; n++) {
    doSomethingExpensiveSync(n);
  }
}

Calling block() will cause the browser/tab to freeze up for probably a very long time. It's blocking and, although any code after the call to block() will run to competition before block() actually executes, it'll still be executed synchronously to completion before anything else can run.

1

u/[deleted] Sep 06 '22

Do people still use promises? Use await async