FYI: I spent a frustrating while realising that deleting a timer from within code called by that timer triggering was a bad idea.
The solution was to use distimer instead.
[this is a summary of a thread on the old nabble forum]
Gotcha: Segmentation Fault in Trigger callback
Re: Gotcha: Segmentation Fault in Trigger callback
If you really want to delete the timer, you could add it to a global list:
Also, you can create a second timer that calls a function in your plugin, that empties @DeleteTimerList periodically.
This should guarantee that you never delete the timer, from within the Perl code it calls. (It's probably simpler to use distimer, as you say.)
Code: Select all
# Create a global variable
our @DeleteTimerList;
# Create a KildClient timer
$::world->timer(
{
name => $timerName,
interval => $timerInterval,
action => $timerAction,
}
);
# When you want to delete the timer, add it to death row
push (@DeleteTimerList, $timerName);
Code: Select all
$::world->timer(
{
name => 'Grim_reaper',
interval => 1,
action => '/myplugin->deleteMyTimers(),
}
);
...
sub deleteMyTimer {
foreach my $timerName (@DeleteTimerList) {
$result = $::world->deltimer($timerName);
}
}