-
Notifications
You must be signed in to change notification settings - Fork 4k
Open
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?
Metadata
Metadata
Assignees
Labels
No labels