javascript - Loop on a promise indefinitely until rejection -
i have function async work , returns promise
, , want execute function indefinitely until promise reject
ed.
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
Post a Comment