728x90
반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// promise2.js | |
function countdown(seconds) { | |
return new Promise(function(resolve, reject) { | |
for(let i=seconds; i>=0; i--) { | |
setTimeout(function() { | |
if(i===13) return reject(new Error("DEFINITELY NOT COUNTING THAT")); | |
if(i>0) console.log(i + '...'); | |
else resolve(console.log("GO!")); | |
}, (seconds-i)*1000); | |
} | |
}); | |
} | |
countdown(15).then( | |
function() { | |
console.log("countdown completed successfully"); | |
}, | |
function(err) { | |
console.log("countdown experienced an error: " + err.message); | |
} | |
); |
728x90
반응형
'Javascript' 카테고리의 다른 글
인류를 위한 ES6 (ES6 for Humans) (0) | 2024.10.27 |
---|---|
terminal-image-cli : 터미널에 이미지 표시 (JS) (1) | 2024.10.25 |
Javascript Promise (0) | 2018.11.22 |
Callback Hell (0) | 2018.11.22 |
Error first callback (0) | 2018.11.22 |