Created
July 2, 2015 18:12
-
-
Save johnbeech/44438abbfcb9410715f8 to your computer and use it in GitHub Desktop.
Simple promises
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
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It should be noted that this doesn't follow:
https://promisesaplus.com/