Snippets

Brian Medley ekdLe: Untitled snippet

Created by Brian Medley last modified
use Mojolicious::Lite;

my $stop_file = "full_stop.stp";

get '/' => sub {
    my $c = shift;

    my $id;
    my $stop_time = time() + 10;

    $c->delay(
        sub {
            my $cb = shift->begin();

            $id = Mojo::IOLoop->recurring(0.1 => sub {
                if (time() > $stop_time) {
                    $cb->();
                }

                if (-f $stop_file) {
                    $c->app->log->debug("stop_file is present: $stop_file");

                    return;
                }

                $cb->()
            });
        },
        sub {
            Mojo::IOLoop->remove($id);

            $c->render(json => { file_present => -f $stop_file ? 1 : 0, text => "Hiya" });
        },
    );
};

app->start;

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.