From f5de4154d0110183daa442faefa4c746a14a7023 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 25 Nov 2021 20:59:08 +0000 Subject: [PATCH] cope with no $idler right after idle is done might be undef'd by an event handler --- lib/App/MPD/Feeder.pm | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/App/MPD/Feeder.pm b/lib/App/MPD/Feeder.pm index 8561cf8..36bf29d 100644 --- a/lib/App/MPD/Feeder.pm +++ b/lib/App/MPD/Feeder.pm @@ -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; -- 2.39.5