diff --git a/lib/PBot/EventQueue.pm b/lib/PBot/EventQueue.pm index c2010eaf..ba9e3dbc 100644 --- a/lib/PBot/EventQueue.pm +++ b/lib/PBot/EventQueue.pm @@ -152,7 +152,7 @@ sub do_events { # we call time for a fresh time, instead of using a stale $now that # could be in the past depending on a previous event's duration if (time >= $self->{event_queue}->get_priority($i)) { - my $event = $self->{event_queue}->get_entry($i); + my $event = $self->{event_queue}->get($i); $self->{pbot}->{logger}->log("Processing event $i: $event->{id}\n") if $debug > 1; @@ -167,7 +167,7 @@ sub do_events { } else { # no more events ready at this time if ($debug > 2) { - my $event = $self->{event_queue}->get_entry($i); + my $event = $self->{event_queue}->get($i); $self->{pbot}->{logger}->log("Event not ready yet: $event->{id} (timeout=$event->{priority})\n"); } @@ -349,7 +349,7 @@ sub update_interval { my ($self, $id, $interval, $dont_enqueue) = @_; for (my $i = 0; $i < $self->{event_queue}->count; $i++) { - my $event = $self->{event_queue}->get_entry($i); + my $event = $self->{event_queue}->get($i); if ($event->{id} eq $id) { if ($dont_enqueue) { diff --git a/lib/PBot/Utils/PriorityQueue.pm b/lib/PBot/Utils/PriorityQueue.pm index d798d9f8..35572de8 100644 --- a/lib/PBot/Utils/PriorityQueue.pm +++ b/lib/PBot/Utils/PriorityQueue.pm @@ -31,7 +31,7 @@ sub count { return scalar @{$self->{queue}}; } -sub get_entry { +sub get { my ($self, $position) = @_; return $self->{queue}->[$position]; } @@ -51,6 +51,8 @@ sub remove { sub find_enqueue_position { my ($self, $priority) = @_; + $priority //= 0; + # no entries in queue yet, early-return first position return 0 if not @{$self->{queue}};