noxxi / p5-net-sip

Net::SIP Perl Module
Other
15 stars 22 forks source link

Is there a method to stop the event loop? #67

Closed kobaz closed 7 months ago

kobaz commented 7 months ago

I've tried a few different ways to kill the event loop:

my $stopvar;

$ua->add_timer($timeout , \$stopvar );

my $ua = Net::SIP::Simple->new();

my $invite = $ua->invite($to, cb_final => sub { print "Got Final!\n"; $stopvar = 1; # Doesn't terminate the loop $ua->loop->shutdown(); # Doesn't terminate the loop (Suggested by chatgpt)

goto done; # Obviously terminates the loop... })

$ua->loop(); done:

Without forcefully using goto to jump out.. I get 'Got Final' to print at the end of my dialog but the loop doesn't stop

My Call flow: ----> INVITE <--- 100 Trying <--- 302 Moved ----> ACK ==== Event loop stays running, but I want it to terminate here.

noxxi commented 7 months ago

If you want to use a stopvar to stop the loop you have to actually use it in the call to loop. To cite from the documentation:

loop ( [ TIMEOUT, @STOPVAR ] )
    ....@STOPVAR is a list of scalar references,
    will stop the loop if any of these references contains TRUE. 

Or as code:

my $stopvar;
$ua->invite(...., cb_final => { $stopvar = 1 });
$ua->loop(undef, \$stopvar);