Created
June 23, 2017 05:52
-
-
Save avalanchy/1c367a17ef4466a6e6554ed70598d173 to your computer and use it in GitHub Desktop.
node fetchUntil.js
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
var request = require('request'); | |
console.log('With callbacks'); | |
var browser = 'Selenium Wrapper'; | |
function getIp (callback) { | |
request('https://api.ipify.org?format=json', function (error, response, body) { | |
if (error) { | |
throw `Cannot connect: ${error}`; | |
} | |
if (Math.random() < 0.8) { | |
console.log('Pretending that there are no IP and trying again'); | |
getIp(callback); | |
return; | |
} | |
var loaded = JSON.parse(body); | |
callback(loaded.ip); | |
}); | |
} | |
getIp((ip) => { | |
console.log(`Here I am making assertions with browser: ${browser} and fetched IP: ${ip}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment