A promise is an object that may produce a single value some time in the future: either a resolved value, or a reason that it’s not resolved (e.g., a network error occurred). A promise may be in one of 3 possible states: fulfilled, rejected, or pending. Promise users can attach callbacks to handle the fulfilled value or the reason for rejection.

Promises are use to avoid callback hell!


const wait = time => new Promise((resolve,reject) => setTimeout(resolve, time));
wait(3000).then(() => console.log('Hello!')); // 'Hello!'

0 commenti

Lascia un commento

Segnaposto per l'avatar