Skip to content

Instantly share code, notes, and snippets.

@cgrinaldi
Created June 14, 2015 23:17
Show Gist options
  • Save cgrinaldi/b64647aeec75e55a9b73 to your computer and use it in GitHub Desktop.
Save cgrinaldi/b64647aeec75e55a9b73 to your computer and use it in GitHub Desktop.
An example where I was using promises all wrong...
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