|
NAMEIO::Lambda::Fork - wait for blocking code in children processes DESCRIPTIONThe module implements the lambda wrapper that allows to wait asynchronously for blocking code in another process' context. "IO::Lambda::Fork" provides a twofold interface for that: the lambda interface, that can wait for the forked child processes, and an easier way for simple communication between these. Contrary to the classical stdin-stdout interaction between parent and child processes, this module establishes a stream socket and uses it instead. The socket can also be used by the caller for its own needs ( see IO::Lambda::Message ). SYNOPSIS use IO::Lambda qw(:lambda);
use IO::Lambda::Fork qw(forked);
Blocking wait lambda {
context forked {
sleep(1);
return "hello!";
};
tail {
print shift, "\n"
}
}-> wait;
# hello!
Non-blocking wait lambda {
context 0.1, forked {
sleep(1);
return "hello!";
};
any_tail {
if ( @_) {
print "done: ", $_[0]-> peek, "\n";
} else {
print "not yet\n";
again;
}
};
}-> wait;
# not yet
# not yet
# not yet
# done: hello!
(of course, since IO::Lambda is inherently non-blocking, the first example is of much more use, as many of such "blocking" lambdas can execute in parallel) API
BUGSDoesn't work on Win32, because relies on $SIG{CHLD} which is not getting delivered (on 5.10.0 at least). However, since Win32 doesn't have forks anyway, Perl emulates them with threads. Consider using IO::Lambda::Thread instead when running on windows. Has issues with SIGCHLD on perls < 5.8.0. AUTHORDmitry Karasik, <dmitry@karasik.eu.org>.
|