Skip to content

Instantly share code, notes, and snippets.

@apostololeg
Last active August 29, 2015 14:02
Show Gist options
  • Save apostololeg/b88890219ce02623a668 to your computer and use it in GitHub Desktop.
Save apostololeg/b88890219ce02623a668 to your computer and use it in GitHub Desktop.
vow promises
var vow = require('vow'),
request = require('request'),
handler = 'http://api.geonames.org/postalCodeLookupJSON?postalcode=6600&country=AT&username=demo';
function getData(remote) {
if(remote) {
var promise = new vow.promise();
request(remote, function(err, req, body) {
promise.fulfill(body);
});
return promise;
} else {
return vow.resolve('none');
}
}
vow.all([
getData(handler),
getData(),
getData(handler),
getData()
])
.then(function(data) {
console.log('------------', data);
});
getData()
.then(function(data) {
console.log('synchronously', data);
});
getData(handler)
.then(function(data) {
console.log('asynchronously', data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment