CC: | powerman [...] powerman.name |
Subject: | Another way to finish a statement |
Async::Defer's POD reads:
Show quoted text
> While you can use both sync and async sub in do(), they all MUST
> call one of done(), throw(), continue() or break() when they
> finish their work
However, I think another way is possible: to call run() method of a
child defer
with $parent_defer being set, as in::
my $parent = Async::Defer->new();
$parent->do(sub {
my ($d, @args) = @_;
... ## some processing
my $child = Async::Defer->new();
$child->do( ... ); ## write some async program
$child->run($d, @args_for_child);
});
$parent->run();
The code dynamically creates a child defer and inserts it into the
execution of the parent defer. This model is very similar to
JSDeferred library for Javascript, in which returned child Deferred
objects are executed between the parent's statements.
In my opinion this way of finishing a statement is sometimes useful,
thus worth noting in POD.
-----
Toshio ITO
debug.ito@gmail.com