Skip to content

Instantly share code, notes, and snippets.

@johnbeech
Created July 2, 2015 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbeech/44438abbfcb9410715f8 to your computer and use it in GitHub Desktop.
Save johnbeech/44438abbfcb9410715f8 to your computer and use it in GitHub Desktop.
Simple promises
module.exports = require('./default-config');
module.exports.environment = 'test';
module.exports.configService = function(query) {
var deferred = {};
deferred.then = function(callback) {
deferred.resolve = callback;
return this;
}
deferred.fail = function(callback) {
deferred.reject = callback;
}
setTimeout(doStuff, 1, query, deferred);
return deferred;
}
function doStuff(query, deferred) {
try {
result = "SECOND require('do-cool-mysql-config-stuff') " + query.hello;
deferred.resolve(result);
}
catch(e) {
deferred.reject(e);
}
}
var configService = module.exports.configService;
var myQuery = {
"hello": "joel"
}
configService(myQuery).then(function(arc) {
console.log("Then " + arc);
}).fail(function(error) {
console.log("Fail " + error);
});
console.log("FIRST")
@subsidel
Copy link

subsidel commented Jul 3, 2015

It should be noted that this doesn't follow:
https://promisesaplus.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment