Async-Defer
view release on metacpan or search on metacpan
my ($d, %taskresults) = @_;
if (ref $taskresults{task1}) {
print "task1 results:", @{ $taskresults{task1} };
} else {
print "task1 throw error:", $taskresults{task1};
}
});
if
else
end_if
$defer = $defer->if( \&conditional );
$defer = $defer->else();
$defer = $defer->end_if();
Add conditional OPERATOR to this object's program.
When this OPERATOR should be executed, \&conditional will be called
with single param:
( $defer_object )
The \&conditional MUST be sync, and return true/false.
while
end_while
$defer = $defer->while( \&conditional );
$defer = $defer->end_while();
Add loop OPERATOR to this object's program.
When this OPERATOR should be executed, \&conditional will be called
with single param:
( $defer_object )
The \&conditional MUST be sync, and return true/false.
try
catch
$defer = $defer->try();
$defer = $defer->catch(
$regex_or_FINALLY => \&sync_or_async_code,
...
);
Add exception handling to this object's program.
In general, try/catch/finally behaviour is same as in Java (and
probably many other languages).
If some STATEMENTS inside try/catch block will throw(), the thrown
error can be intercepted (using matching regexp in catch()) and handled
in any way (blocked - if catch() handler call done(), continue() or
break() or replaced by another exception - if catch() handler call
throw()). If exception match more than one regexp, first successfully
matched regexp's handler will be used. Handler will be executed with
params:
( $defer_object, $error )
In addition to exception handlers you can also define FINALLY handler
(by using string "FINALLY" instead of regex). FINALLY handler will be
called in any case (with/without exception) and may handle this in any
way just like any other exception handler in catch(). FINALLY handler
will be executed with different params:
# with exception
( $defer_object, $error)
# without exception
( $defer_object, @optional_results_from_previous_STATEMENT )
FLOW CONTROL in STATEMENTS
Unless you are nesting child defers, one and only one of these methods
MUST be called at end of each STATEMENT, both sync and async! In the
case of nested defers, see "NESTED DEFERS".
done
$defer->done( @optional_result );
Go to continue STATEMENT/OPERATOR. If continue is STATEMENT, it will
receive @optional_result in it parameters.
throw
$defer->throw( $error );
Throw exception. Nearest matching catch() or FINALLY STATEMENT will be
executed and receive $error in it parameter.
continue
$defer->continue();
Move to beginning of nearest while() (or to first STATEMENT if called
outside while()) and continue with continue iteration (if while()'s
\&conditional still returns true).
break
$defer->break();
Move to first STATEMENT/OPERATOR after nearest while() (or finish this
program if called outside while() - returning to parent's Defer object
if any).
SUPPORT
Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at
https://github.com/powerman/perl-Async-Defer/issues. You will be
( run in 0.816 second using v1.01-cache-2.11-cpan-39bf76dae61 )