From 87a8a1801438d16c81aee928ac228bf9ed3e3485 Mon Sep 17 00:00:00 2001 From: Pedro Melo Date: Sun, 20 Jul 2014 16:49:17 +0100 Subject: [PATCH] Catch and warn of errors, exit the script if one shows up Signed-off-by: Pedro Melo --- examples/consumer.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/consumer.pl b/examples/consumer.pl index 10e557d..09cd5d6 100755 --- a/examples/consumer.pl +++ b/examples/consumer.pl @@ -10,6 +10,8 @@ use AnyEvent::NSQ::Reader; my ($topic, $channel) = @ARGV; die "Usage: consumer.pl topic channel\n" unless $topic and $channel; +my $cv = AE::cv; + my $c = 1; my $r = AnyEvent::NSQ::Reader->new( topic => $topic, @@ -19,6 +21,8 @@ my $r = AnyEvent::NSQ::Reader->new( # message_cb => sub {print STDERR "$c: $_[1]{message}\n";$c++; return}, ## return undef => mark_as_done_msg() message_cb => sub {return}, ## return undef => mark_as_done_msg() + + error_cb => sub { warn "FATAL: got error message '$_[1]', exiting...\n"; $cv->send }, ); -AE::cv->recv; +$cv->recv;