Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
Mojolicious::Plugin::FUseraContributed Perl DoMojolicious::Plugin::ForkCall(3)

       Mojolicious::Plugin::ForkCall - run blocking code asynchronously	in
       Mojolicious applications	by forking

	use Mojolicious::Lite;

	plugin 'Mojolicious::Plugin::ForkCall';

	get '/slow' => sub {
	  my $c	= shift;
	  my @args = ...;
	    sub	{
	      my @args = @_;
	      return do_slow_stuff(@args);
	    sub	{
	      my ($c, @return) = @_;
	      $c->render(json => \@return);



       Registering Mojolicious::Plugin::ForkCall adds a	helper method
       "fork_call" to your Mojolicious application, making it easy to start
       code in a forked	process	using Mojo::IOLoop::ForkCall.

       Note that it does not increase the timeout of the connection, so	if
       your forked process is going to take a very long	time, you might	need
       to increase that	using "inactivity_timeout" in

       This module adds	the following helper method to your application:

	  sub {
	    my @args = @_;
	    # This code	is run in a forked process
	    return @return;
	  [$arg1, $arg2, $arg3], # Optional arguments passed to	the above code
	  sub {
	    my ($c, @return) = @_;
	    # This code	is run in the current process once the child exits

       The "fork_call" helper takes up to 3 arguments: a required code
       reference to be run in a	forked child process, an optional array
       reference of arguments to be passed to the child	code, and a required
       code reference to be run	in the parent as a callback. The callback is
       passed the controler instance and return	values of the child.

       The helper relies on the	Mojolicious core helper	"delay"	in
       Mojolicious::Plugin::DefaultHelpers and as such it will render an
       exception (500) page if any uncaught exception occurs in	the child
       process or in the parent	callback. This also means that the parent
       callback	will not be called if the child	process	encounters an

       This helper is a	convenience only and is	not indended for complex
       cases.  If you need to configure	the Mojo::IOLoop::ForkCall instance or
       want to "fork and forget" a child, you should use the class directly
       rather than this	helper.	If more	complicated delays are required, you
       should use the "delay" in Mojolicious::Plugin::DefaultHelpers helper or
       "delay" in Mojo::IOLoop method directly,	along with an instance of

perl v5.32.0			  2020-08-13  Mojolicious::Plugin::ForkCall(3)


Want to link to this manual page? Use this URL:

home | help