Created
December 31, 2016 17:19
-
-
Save Lazhari/180d12be2a2e7fe38eb111d34f7bdba3 to your computer and use it in GitHub Desktop.
JavaScript generators using co and request-promise-native
This file contains hidden or 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
const request = require('request-promise-native'); | |
const co = require('co'); | |
const getWebPage = co.wrap(function * (url) { | |
let body; | |
try { | |
body = yield request({ | |
uri: url, | |
method: 'GET' | |
}) | |
} catch (err) { | |
console.error('getGooglePage() error:', err); | |
throw err; | |
} | |
return body; | |
}); | |
getWebPage('https://google.com') | |
.then(page => console.log(page)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment