Jonathan H
2016-Nov-18 11:50 UTC
[asterisk-users] Any way of just killing ALL stray WHILE loops?
tl;dr Is there ANY way/hack of just telling Asterisk to destroy *all* WHILE loops it may be nested in at a certain time? Reason: you know the thing about WHILE loops not only having to have "seen" their endwhile to finish properly? If not, a reminder before it gives you 3am sleepless nights: https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Application_While?focusedCommentId=36798737#comment-36798737 * While marks the start of a while loop in the dialplan as well as the condition to keep executing the loop. For the While to terminate the loop, the loop's EndWhile must have been executed before. This implies that the while condition must have been true at least once. * EndWhile marks the end of the while loop. * ExitWhile breaks out of the while loop and jumps to the loop's EndWhile location. For ExitWhile to know where to go, the loop's EndWhile must have been executed before. * ContinueWhile jumps to the current while loop's While location. What this means is that all while loops have to have two extra conditions if something might happen during them: 1: a seperate condition that is true for 1 loop and skips running things in that loop 2: something to catch and deal with it First context good, second context bad. But now I have a nested loop, there's no way of avoiding it, and a keypress might be made in either the outer OR inner loop. It's really baking my noodle. I just want all loops to die as soon as a keypress is made. Am I missing a trick here? [while-loop-tester] exten => s,1,Set(n=0) same => n,While($[${n} <= 9]) same => n,GotoIf($[${n} < 1]?end); hacky workaround so while does 1 loop and knows where endwhile is same => n,BackGround(press-${n}&for&digits/${n}) same => n(end),Set(n=${INC(n)}) same => n,EndWhile() same => n,WaitExten(3); same => n,Goto(s,1) exten => _[1-8],1,Set(chosenNumber=${EXTEN}) same => n,Playback(digits/${chosenNumber}) same => n,Set(n=99) ; will make WHILE think it's done. same => n,ExitWhile() ; MUST do this to ensure we've broken out of loop same => n,Goto(s,1) [while-loop-tester-fail] exten => s,1,Set(n=0) same => n,While($[${n} <= 9]) same => n,BackGround(press-${n}&for&digits/${n}) same => n,Set(n=${INC(n)}) same => n,EndWhile() same => n,WaitExten(3); same => n,Goto(s,1) exten => _[1-8],1,Set(chosenNumber=${EXTEN}) same => n,Playback(digits/${chosenNumber}) same => n,Set(n=99) same => n,ExitWhile() ; But this will throw an error as it doesn't know where the while end is same => n,Goto(s,1)