javascript - Executing a series of $timeouts -
i'm working on angularjs app. app needs alternate time outs. alternating handled array. array looks [3000, 1000, 3000, 1000, 5000].
this array means run operation 3 seconds. then, wait 1 second. run operation 3 seconds. wait second. finally, run operation 5 seconds. operations differ. either way, i'm not sure how execute them in sequence.
how execute series of $timeout elements in angularjs?
thank you!
this sounds better done custom timer because need keep track of time, not delay operation.
somehow, need format data have amount of run , pause time each operation. this:
var operations = [{fun: onefunction, wait: 1000, run: 3000}, {fun: twofunction, wait: 2000, run: 5000]; then need handle functions, running them respective times:
function handleoperations(operationarray) { (var = 0; < operationarray.length; i++) { var start = date.now(); if ((date.now()-start) <= operationarray[i].run) { operationarray[i].fun(); //run while timer still going } else { //otherwise, wait specified time var waitstart = date.now(); if ((date.now()-waitstart) <= operationarray[i].wait) {}; } } }
Comments
Post a Comment