Created
March 3, 2016 23:17
-
-
Save rrmdn/7ca5fb0840ff01caa9ad to your computer and use it in GitHub Desktop.
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
| // read directory source path | |
| function bacaDirektori(source) { | |
| return new Promise(function (resolve, reject) { | |
| fs.readdir(source, function (err, files) { | |
| if(err) reject(err) | |
| else resolve(files) | |
| }) | |
| }) | |
| } | |
| // penggunaan | |
| bacaDirektori(source) | |
| .then(function (files) { | |
| // jika resolve(files) maka fungsi ini yang di panggil | |
| // ingin melanjutkan dengan promise? tinggal return new Promise disini, | |
| // agar bisa chained .then() | |
| }) | |
| .catch(function (err) { | |
| // jika reject(err) maka fungsi ini yang terpanggil | |
| }) | |
| .then() | |
| .then() | |
| .then() | |
| // dan .then() seterusnya |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment