diff --git a/PBot/Timer.pm b/PBot/Timer.pm index 9ea37b14..cd3cf949 100644 --- a/PBot/Timer.pm +++ b/PBot/Timer.pm @@ -184,14 +184,14 @@ sub enqueue_event { my $i = $self->find_enqueue_position($event->{timeout}); splice @{$self->{event_queue}}, $i, 0, $event; - if ($interval < $waitfor) { - $self->waitfor($interval); - } - my $debug = $self->{pbot}->{registry}->get_value('timer', 'debug') // 0; if ($debug > 1) { $self->{pbot}->{logger}->log("Enqueued new timer event $id at position $i: timeout=$event->{timeout} interval=$interval repeating=$repeating\n"); } + + if ($interval < $waitfor) { + $self->waitfor($interval); + } } sub dequeue_event { @@ -290,11 +290,11 @@ sub on_tick_handler { } } - $self->waitfor($next_tick); - foreach my $event (@enqueue) { $self->enqueue_event($event->{subref}, $event->{interval}, $event->{id}, 1); } + + $self->waitfor($next_tick); } else { # no queued events, call default overridable on_tick() method if timeout has elapsed if ($seconds - $self->{last} >= $self->{timeout}) {