Any Way Of Just Killing ALL Stray WHILE Loops?

Home » Asterisk Users » Any Way Of Just Killing ALL Stray WHILE Loops?
Asterisk Users No Comments

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?focusedCommentId6798737#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