Skip to content

Promise basics loading indicator example #3286

@bogdanbacosca

Description

@bogdanbacosca

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions