javascript - How to loop a promise in for loop and break if condition met -
i new using promise , breaking head solve this. want run script until condition met in protractor below code it's not working. how fix this?
let counter = 30; (let = 0; < counter; i++) { browser.executescript(somescript).then((value) => { //console.log(value); if (value > 0) //do stuff } else { return; //exit loop --not working //or i=counter;// exit if , counter value same } }) }
i have limitedretry
code appear need
limitedretry = (cont, fn) => fn().catch(err => cont > 0 ? limitedretry(cont - 1, fn) : promise.reject(err));
your use be
limitedretry(30, function() { browser.executescript(somescript).then((value) => { if (value > 0) { // stuff return 'this resolved value of promise'; } else { return promise.reject('try again'); } }); }) .then(v => console.log(v)) .catch(err => console.log(err));
Comments
Post a Comment