Created
June 14, 2015 23:17
-
-
Save cgrinaldi/b64647aeec75e55a9b73 to your computer and use it in GitHub Desktop.
An example where I was using promises all wrong...
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'); | |
var getConfig = function() { | |
// Using promises because fs.readFile() is async | |
var deferred = Q.defer(); | |
fs.readFile(__dirname + '/../../aFile.conf', 'utf-8', function(err, data) { | |
if (err) { | |
deferred.reject(err); | |
} | |
var configJSON = helpers.config2JSON(data, true); // true indicates we are parsing the input section | |
deferred.resolve(configJSON); | |
}); | |
return deferred.promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment