Mojo::IOLoop::Thread - Threaded Replacement for Mojo::IOLoop::subprocess
use Mojo::IOLoop::Thread; # Operation that would block the event loop for 5 seconds my $subprocess = Mojo::IOLoop::Thread->new; $subprocess->run( sub { my $subprocess = shift; sleep 5; return '♥', 'Mojolicious'; }, sub { my ($subprocess, $err, @results) = @_; say "Subprocess error: $err" and return if $err; say "I $results[0] $results[1]!"; } ); # Start event loop if necessary $subprocess->ioloop->start unless $subprocess->ioloop->is_running;
or
use Mojo::IOLoop; use Mojo::IOLoop::Thread; my $iol = Mojo::IOLoop->new; $iol->subprocess( sub {'♥'}, sub { my ($subprocess, $err, @results) = @_; say "Subprocess error: $err" and return if $err; say @results; } ); $loop->start;
Mojo::IOLoop::Thread is a multithreaded alternative for Mojo::IOLoop::Subprocess which is not available under Win32. It is a dropin replacement, takes the same parameters and works analoguous by just using threads instead of forked processes.
Mojo::IOLoop::Thread replaces "subprocess" in Mojo::IOLoop with a threaded version on module load. Please make sure that you load Mojo::IOLoop first.
Thomas Kratz <tomk@cpan.org>
https://github.com/tomk3003/mojo-ioloop-thread
Copyright 2017 Thomas Kratz.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Mojo::IOLoop::Thread, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::IOLoop::Thread
CPAN shell
perl -MCPAN -e shell install Mojo::IOLoop::Thread
For more information on module installation, please visit the detailed CPAN module installation guide.