]> git.ktnx.net Git - mpd-feeder.git/commitdiff
keep $loop variable at closure reach
authorDamyan Ivanov <dmn@debian.org>
Thu, 25 Nov 2021 20:58:17 +0000 (20:58 +0000)
committerDamyan Ivanov <dmn@debian.org>
Thu, 25 Nov 2021 20:58:17 +0000 (20:58 +0000)
otherwise it can't be stopped from within the closure, and $mpd->loop
may be the thing from re-init-ed $mpd (after a reconnect)

lib/App/MPD/Feeder.pm

index c951c70e8dc6134a7cbdda903042445e43f17d9f..8561cf8206eeae69dc02596cb73c5da7cb18d7a8 100644 (file)
@@ -91,6 +91,8 @@ method init_mpd {
         }
     );
 
+    my $loop = $mpd->loop;
+
     my $int_signal_handler = sub {
         state $signal_count = 0;
         $signal_count++;
@@ -103,12 +105,12 @@ method init_mpd {
 
         $log->debug("Signal received. Stopping loop");
         $quit_requested = 1;
-        $mpd->loop->stop('quit');
+        $loop->stop('quit');
         $self->break_idle;
     };
 
     for (qw(TERM INT)) {
-        $mpd->loop->add(
+        $loop->add(
             IO::Async::Signal->new(
                 name       => $_,
                 on_receipt => $int_signal_handler,
@@ -116,19 +118,19 @@ method init_mpd {
         );
     }
 
-    $mpd->loop->add(
+    $loop->add(
         IO::Async::Signal->new(
             name       => 'HUP',
             on_receipt => sub {
                 $log->debug("SIGHUP received. Scheduling reload");
                 $reload_requested = 1;
-                $mpd->loop->stop('reload');
+                $loop->stop('reload');
                 $self->break_idle;
             },
         )
     );
 
-    $mpd->loop->add(
+    $loop->add(
         IO::Async::Signal->new(
             name       => 'USR1',
             on_receipt => sub {
@@ -371,12 +373,15 @@ method run_loop {
 
     $self->init_mpd;
 
-    $mpd->loop->add(
+    my $loop = $mpd->loop;
+
+    $loop->add(
         IO::Async::Timer::Periodic->new(
             interval => 60,
             on_tick  => sub {
                 if (!$mpd_connected) {
                     $log->trace("Not connected to MPD. Skipping alive check.");
+                    $loop->stop('disconnected');
                     return;
                 }