JavaScriptのPromise 5
JavaScriptのPromise
by Jirobe
TypeScript
let count = 0;
function promiseTest(): Promise {
console.log(++count);
return new Promise((resolve, reject) => {
if(count > 0){reject();}
resolve();
});
}
promiseTest()
.then( () => {
console.log(++count);})
.then( () => {
console.log(++count);})
.then( () => {
console.log(++count);})
.then( () => {
console.log(++count);})
.then( () => {console.log(`last:` + count);})
.catch(() => {console.log(`failure`);});