NAME
IO::Lambda::Fork - wait for blocking code using coprocesses
DESCRIPTION
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.
SYNOPSIS
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;
API
- new($class, $code)
-
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. - kill $sig = 'TERM'
-
Sends a signal to the process, executing the blocking code.
- forked($code)
-
Same as
new
but without a class. - pid
-
Returns pid of the coprocess.
- socket
-
Returns the associated stream
- join
-
Blocks until process is finished.
BUGS
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 IO::Lambda::Threads instead when running on windows.
AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>.