1Mail::SpamAssassin::TimUesoeurt(C3o)ntributed Perl DocumMeanitla:t:iSopnamAssassin::Timeout(3)
2
3
4

NAME

6       Mail::SpamAssassin::Timeout - safe, reliable timeouts in perl
7

SYNOPSIS

9           # non-timeout code...
10
11           my $t = Mail::SpamAssassin::Timeout->new({ secs => 5, deadline => $when });
12
13           $t->run(sub {
14               # code to run with a 5-second timeout...
15           });
16
17           if ($t->timed_out()) {
18               # do something...
19           }
20
21           # more non-timeout code...
22

DESCRIPTION

24       This module provides a safe, reliable and clean API to provide
25       alarm(2)-based timeouts for perl code.
26
27       Note that $SIG{ALRM} is used to provide the timeout, so this will not
28       interrupt out-of-control regular expression matches.
29
30       Nested timeouts are supported.
31

PUBLIC METHODS

33       my $t = Mail::SpamAssassin::Timeout->new({ ... options ... });
34           Constructor.  Options include:
35
36           secs => $seconds
37               time interval, in seconds. Optional; if neither "secs" nor
38               "deadline" is specified, no timeouts will be applied.
39
40           deadline => $unix_timestamp
41               Unix timestamp (seconds since epoch) when a timeout is reached
42               in the latest.  Optional; if neither secs nor deadline is
43               specified, no timeouts will be applied. If both are specified,
44               the shorter interval of the two prevails.
45
46       $t->run($coderef)
47           Run a code reference within the currently-defined timeout.
48
49           The timeout is as defined by the secs and deadline parameters to
50           the constructor.
51
52           Returns whatever the subroutine returns, or "undef" on timeout.  If
53           the timer times out, "$t-<gt"timed_out()> will return 1.
54
55           Time elapsed is not cumulative; multiple runs of "run" will restart
56           the timeout from scratch. On the other hand, nested timers do
57           observe outer timeouts if they are shorter, resignalling a timeout
58           to the level which established them, i.e. code running under an
59           inner timer can not exceed the time limit established by an outer
60           timer. When restarting an outer timer on return, elapsed time of a
61           running code is taken into account.
62
63       $t->run_and_catch($coderef)
64           Run a code reference, as per "$t-<gt"run()>, but also catching any
65           "die()" calls within the code reference.
66
67           Returns "undef" if no "die()" call was executed and $@ was unset,
68           or the value of $@ if it was set.  (The timeout event doesn't count
69           as a "die()".)
70
71       $t->timed_out()
72           Returns 1 if the most recent code executed in "run()" timed out, or
73           "undef" if it did not.
74
75       $t->reset()
76           If called within a "run()" code reference, causes the current alarm
77           timer to be restored to its original setting (useful after our
78           alarm setting was clobbered by some underlying module).
79
80
81
82perl v5.30.0                      2019-10-01    Mail::SpamAssassin::Timeout(3)
Impressum