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)
}
);
+ my $loop = $mpd->loop;
+
my $int_signal_handler = sub {
state $signal_count = 0;
$signal_count++;
$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,
);
}
- $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 {
$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;
}