Last active
January 16, 2017 05:24
-
-
Save bepitulaz/3c5345394908357d1756395ca576eba5 to your computer and use it in GitHub Desktop.
Memahami Promise Bagian 2
This file contains hidden or 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
| var promiseOne = new Promise(function(resolve, reject) { | |
| setTimeout(function() { | |
| resolve('promise 1 sukses'); | |
| }, 2000); | |
| }); | |
| var promiseTwo = new Promise(function(resolve, reject) { | |
| setTimeout(function() { | |
| resolve('promise 2 sukses'); | |
| }, 3000); | |
| }); | |
| // masukkan kedua object Promise di atas ke dalam array | |
| var batchProcessed = [promiseOne, promiseTwo]; | |
| Promise.all(batchProcessed).then(function(result) { | |
| // kedua Promise di atas resolve | |
| console.log(result); // hasilnya akan berbentuk array: ["promise 1 sukses", "promise 2 sukses"] | |
| }).catch(function(error) { | |
| // salah satu atau kedua Promise di atas reject | |
| console.log(error); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment