「Promise.all」と「Promise.resolve」の例です。
Promise.all([ Promise.resolve(100), Promise.resolve(200), Promise.resolve(300) ]) .then( val => console.log('○', val), val => console.log('×', val) );
○ (3) [100, 200, 300]
「Promise.all」と「Promise.reject」の例です。
Promise.all([ Promise.resolve(100), Promise.resolve(200), Promise.reject(300) ]) .then( val => console.log('○', val), val => console.log('×', val) );
× 300
「Promise.allSettled」の例です。
Promise.allSettled([ Promise.resolve(100), Promise.resolve(200), Promise.reject(300) ]) .then(values => console.log(values));
[ {"status": "fulfilled", "value": 100}, {"status": "fulfilled", "value": 200}, {"status": "rejected", "reason": 300} ]
「then」を持ったオブジェクトを利用した「Promise.resolve」の例です。
const thenable = { then: (func1, func2) => { setTimeout(() => { func1('実行'); }, 500); } }; Promise.resolve(thenable) .then(res => { console.log(res); });
実行
種類 | 無料版 | 有料版 |
---|---|---|
頒布先 | Amazon | Booth |
形態 | Kindle電書 | PDF+コード |
価格 | 0円 | 500円 |
目的 | 知識普及 安価に閲覧 | 作者応援 自由な環境で閲覧 |
DRM | あり | なし |
マンガ | ○ | ○ |
コラム | ○ | ○ |
実行可能な コード | × | ○ |