Skip to content

Instantly share code, notes, and snippets.

@seanstrom
Last active August 29, 2015 14:13
Show Gist options
  • Save seanstrom/b55ae0a7855fc2e51701 to your computer and use it in GitHub Desktop.
Save seanstrom/b55ae0a7855fc2e51701 to your computer and use it in GitHub Desktop.
Async JS/Node - Promises Always Async example
var http = require('special-http')
function getData(endpoint, callback) {
var promise = new Promise(function(resolver, rejector) {
if(cache[endpoint]) {
return resolver(cache[endpoint])
}
http.get(endpoint).then(function(data) {
resolver(data)
}, function(err) {
rejector(err)
})
})
return promise
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment