ePages 6.17.17 - DE_EPAGES/Core/API/Alarm.pm

Package DE_EPAGES::Core::API::Alarm

provides functions to interrupt other function based on a timer

@EXPORT_OK
Alarm

Functions

Alarm

Alarm

Use this function to execute a possible long-running procedure. When the specified timeout is reached before the procedure has finished, it calls the OnTimeout handler.

Syntax
Alarm( %Options );
Example
Alarm(
    Sub => sub { sleep(30); },
    Timeout => 20,
    OnTimeout => sub { print "timeout\n"; }
);
Input
%Options (hash)
  • Sub - possible long-running code block - code ref
  • Timeout - timeout in seconds - int
  • OnTimeout - code to execute in case of a timeout.
    Important: make sure to call only re-entrant functions
    from here, because the timeout may interrupt the main code
    at an arbitrary position. Any changes to global state may
    change the behaviour of the main code - code ref