Created
February 5, 2014 10:28
-
-
Save medikoo/8820787 to your computer and use it in GitHub Desktop.
Example from StrongLoop article -> http://strongloop.com/strongblog/node-js-callback-hell-promises-generators/ implemented with deferred promise library
This file contains 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 fs = require('fs') | |
, join = require('path').join | |
, promisify = require('deferred').promisify | |
, readdir = promisify(fs.readdir), lstat = promisify(fs.lstat); | |
module.exports = function (dir) { | |
var largest = null, largestSize = -1; | |
return readdir(dir).map(function (file) { | |
return lstat(join(dir, file))(function (stats) { | |
if (!stats.isFile()) return; | |
if (stats.size <= largestSize) return; | |
largest = file; | |
largestSize = stats.size; | |
}); | |
})(function () { return largest; }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment