IO::Lambda::Fork - wait for blocking code using coprocesses
The module implements a lambda wrapper that allows to asynchronously
wait for blocking code. The wrapping is done so that the code is
executed in another process's context. IO::Lambda::Fork inherits
from IO::Lambda, and thus provides all function of the latter to
the caller. In particular, it is possible to wait for these objects
using tail, wait, any_tail etc standard waiter function.
use IO::Lambda qw(:lambda);
use IO::Lambda::Fork qw(forked);
lambda {
context 0.1, forked {
select(undef,undef,undef,0.8);
return "hello!";
};
any_tail {
if ( @_) {
print "done: ", $_[0]-> peek, "\n";
} else {
print "not yet\n";
again;
}
};
}-> wait;
Creates a new IO::Lambda::Fork object in the passive state. When the lambda
will be activated, a new process will start, and $code code will be executed
in the context of this new process. Upon successfull finish, result of $code
in list context will be stored on the lambda.
Sends a signal to the process, executing the blocking code.
forked($code)Same as new but without a class.
Returns pid of the coprocess.
Returns the associated stream
Blocks until process is finished.
Doesn'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. Use the IO::Lambda::Threads manpage instead when
running on windows.
Dmitry Karasik, <dmitry@karasik.eu.org>.