Skip to content

Commit

Permalink
List of cows as promise (#45)
Browse files Browse the repository at this point in the history
Allows users of the library to `await` for it

Closes #44
  • Loading branch information
piuccio authored Nov 2, 2018
1 parent 13d6248 commit 79b1aed
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/cows.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ exports.get = function (cow) {
}

exports.list = function (callback) {
fs.readdir(cowsPath, function (err, files) {
if (err) return callback(err);

return callback(null, cowNamesFromFiles(files));
return new Promise(function (resolve, reject) {
fs.readdir(cowsPath, function (err, files) {
if (err) {
reject(err);
callback(err);
} else {
resolve(files);
callback(null, cowNamesFromFiles(files));
}
});
});
}

Expand Down

0 comments on commit 79b1aed

Please sign in to comment.