Skip to content

Instantly share code, notes, and snippets.

@rrmdn
Created March 3, 2016 23:17
Show Gist options
  • Select an option

  • Save rrmdn/7ca5fb0840ff01caa9ad to your computer and use it in GitHub Desktop.

Select an option

Save rrmdn/7ca5fb0840ff01caa9ad to your computer and use it in GitHub Desktop.
// 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