Parallel requests in Mojolicious application

余生长醉 提交于 2019-12-04 14:18:05

In this case you need to disable automatic rendering by calling method render_later from the controller. (http://mojolicio.us/perldoc/Mojolicious/Controller#render_later)

Just add the next string to search controller:

$self->render_later;

Complete example:

#!/usr/bin/perl -wl
use Mojolicious::Lite;

get '/' => sub {
    my $self = shift;
    $self->render_later;
    my $delay = Mojo::IOLoop->delay(sub {
        $self->app->log->debug('Delay finished!');
        $self->render(text => 'test!');
    });
    for my $i (0 .. 5) {
        my $end = $delay->begin;
        Mojo::IOLoop->timer($i => sub {
            $self->app->log->debug($i);
            $end->();
        });
    }
};

app->start;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!