ES6 Promise | SoloLearn: Learn to code for FREE!

+1

ES6 Promise

This code deserves a better detailed explanation, step by step. I have never used this kind of thing before and I wonder in what cases it can be useful. say it's more readable .. heuuu lol. Maybe with the braces in colone, it's a little more readable. _________________________________________________________________________ function asyncFunc(work) { return new Promise(function(resolve, reject) { if (work === "") reject(Error("Nothing")); setTimeout(function() { resolve(work); }, 1000); }); } asyncFunc("Work 1") // Task 1 ***************** >Step 1 .then(function(result) // { console.log(result); return asyncFunc("Work 2"); // Task 2 }, function(error) { console.log(error); }) .then(function(result) { console.log(result); }, function(error) { console.log(error); }); console.log("End"); _______________________________________________________________________ Question: promise is natif object ? Anyway, I hope I never need it

6/15/2020 12:43:35 PM

Alain Mazy

2 Answers

New Answer

+1

Here is my video tutorial series about JavaScript Asynchronous Programming https://www.youtube.com/playlist?list=PLkqwj9vc20pX36wThr2A6DZx4MVcJvnhe Explaining Promise and then proceed to async await and fetch, and at last web scraping. These were recorded before I had bought a nice microphone, so please tolerate the low sound volume.

0

Thanks. ;)