jquery - Loop pause with Q -


I'm using Q for some sequence of jQuery sequential processing in the text (). Now I've added a break button to temporarily stop the processing inside the forEach loop, but if I inside an promise.delay (300) < / code> Add -loop (see partial code below) My browser is hanging

  var promise = new Q (); How do I apply a conditional block on a  forEach  loop in Boolean  ispaused  using Q? Promise = promise Then (function () {lines.forEach (function (item) {// start hanging in the browser if it is then imposed == true promise = promise. Then (function () {while (status) {promise = promise Delay (300);}}) None of the following work, while // (status) {// promise = promise .Delay (300); //} // following either // work If not (IsPaused) {// Q.delay (300); //} (item [0] == '%') {promise = promise. Then (function () {return addprrompt (wnd);} ) Promise = promise again (function () (addoinput (item.substr (1))}}} other {promise = wa Then (function () {addOutput (item, wnd)}}}}}}); Promise = promise then (function () {return addPrompt (wnd);}}}); promise.done ();    

Promise is still asynchronous in this case. While (True)

You can not just do the while (position) {/ * block which is plain old browser javascript in 'condition' / * } . The code that changes is paused in your case and you will never get the opportunity to execute it. (Well, you can do with ES6 generator which gives you explicit control, but this OT is here).

You need the series to promise promise instead of promise.

  promise = promise. Then (function pollUntil () {return Q.delay (300) .then (function () {// recursively chain here the continuity. MS / // will check. Return: pollUntil (): true;});});   

It reads in this form: Continue with the era of poll in the present era, which delays up to 300 milliseconds, and repeats itself (call itself) till now Not true.

Note

Definitely it would be better break () to promise which will solve you now while not halted.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -