]> git.ktnx.net Git - mpd-feeder.git/commitdiff
cope with no $idler right after idle is done
authorDamyan Ivanov <dmn@debian.org>
Thu, 25 Nov 2021 20:59:08 +0000 (20:59 +0000)
committerDamyan Ivanov <dmn@debian.org>
Thu, 25 Nov 2021 20:59:08 +0000 (20:59 +0000)
might be undef'd by an event handler

lib/App/MPD/Feeder.pm

index 8561cf8206eeae69dc02596cb73c5da7cb18d7a8..36bf29d0fd3c643be97397741ca672e3c6dc3455 100644 (file)
@@ -346,23 +346,25 @@ method pulse {
 
     $log->trace('got out of idle');
 
-    if ( $idler->is_done ) {
-        my $result = $idler->get;
-        undef $idler;
-        if ( ref $result and $result->{changed} ) {
-            my $changed = $result->{changed};
-            $changed = [$changed] unless ref $changed;
-
-            $mpd->emit($_) for @$changed;
+    if ($idler) {
+        if ( $idler->is_done ) {
+            my $result = $idler->get;
+            undef $idler;
+            if ( ref $result and $result->{changed} ) {
+                my $changed = $result->{changed};
+                $changed = [$changed] unless ref $changed;
+
+                $mpd->emit($_) for @$changed;
+            }
+        }
+        elsif ( $idler->is_cancelled ) {
+            $log->trace("idle was cancelled");
+            undef $idler;
+        }
+        elsif ( $idler->is_failed ) {
+            $log->warn("idle failed: ".$idler->failure);
+            undef $idler;
         }
-    }
-    elsif ( $idler->is_cancelled ) {
-        $log->trace("idle was cancelled");
-        undef $idler;
-    }
-    elsif ( $idler->is_failed ) {
-        $log->warn("idle failed: ".$idler->failure);
-        undef $idler;
     }
 
     $mpd->loop->stop;