javascript - Loop on a promise indefinitely until rejection -


i have function async work , returns promise, , want execute function indefinitely until promise rejected.

something following :

dosomethingasync().     .then(dosomethingasync)     .then(dosomethingasync)     .then(dosomethingasync)     // ... until rejection 

i made little codepen can test potential solutions : http://codepen.io/jesmodrazik/pen/pbaovz?editors=0011

i found several potential answers nothing seems work case.

if has solution, i'd glad, because can't find !

thanks.

you can do

(function loop(){      dosomethingasync().then(loop); })(); 

but looking @ pen it's not clear rejection should come from. if want stop repeating operation when user clicks button, can change state in button handling , do

(function loop(){      dosomethingasync().then(function(){           if (!stopped) loop();      }); })(); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -