javascript-tutorial / javascript-tutorial/en.javascript.info

Promise basics loading indicator example

Open
#3,286 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
25.5k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

So I was wrapping my head around why would the loading indicator stay active if the promise was settled? The solution did not clarify everything for me, the best explanation I found is:

new Promise((resolve, reject) => {
  /* do something that takes time, and then call resolve or maybe reject */
  const loading = document.createElement('img');
  loading.src="https://media3.giphy.com/media/3oEjI6SIIHBdRxXI40/giphy.gif?cid=ecf05e471sfq2igav6mmdj3cvn1mr4j6br7k3tmo4jvg5t5u&rid=giphy.gif&ct=g";
  document.body.append(loading);
})
*!*
  // runs when the promise is settled, doesn't matter successfully or not
  doSomething().finally(() => loading.remove());
  // so the loading indicator is always stopped before we go on
*/!*
  .then(result => show result, err => show error)

Could something like this improve the example?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Promise basics loading-indicator example discussed in the issue and review how it explains settled promises. Compare the example with the proposed finally-based cleanup, then update the tutorial if it makes the behavior clearer and verify that the explanation covers both successful and rejected promises.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.