#!/usr/bin/env perl use Mojolicious::Lite -signatures; use Mojo::IOLoop; get '/' => sub ($c) { $c->render(template => 'index'); } => 'index'; post '/doit' => sub ($c) { $c->render_later; Mojo::IOLoop->subprocess->run_p(sub { # this code is actually running in a subprocess! sleep 10; return "I did the thing!"; })->then(sub (@results) { $c->render(text => "@results"); })->catch(sub ($err) { $c->reply->exception($err); }); } => 'doit'; app->start; __DATA__ @@ index.html.ep % layout 'main', title => 'Hello, World!';
%= form_for doit => ( method=>'post' ) => begin %= submit_button 'Do the thing' %= end
@@ layouts/main.html.ep <%= title %> %= content