Skip to content

Instantly share code, notes, and snippets.

@avalanchy
Created June 23, 2017 05:52
Show Gist options
  • Save avalanchy/1c367a17ef4466a6e6554ed70598d173 to your computer and use it in GitHub Desktop.
Save avalanchy/1c367a17ef4466a6e6554ed70598d173 to your computer and use it in GitHub Desktop.
node fetchUntil.js
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