Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Example counter PSGI app for Twiggy server

View counter.psgi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# Invoke with:
# twiggy counter.psgi
 
use AnyEvent;
 
my @timers;
$main::timer = AnyEvent->timer(after => 2, interval => 2, cb => sub {
@timers = grep { $_->() } @timers;
});
 
my $app = sub {
my $env = shift;
 
return sub {
my $respond = shift;
my $writer = $respond->([200, ['Content-Type', 'text/html']]);
my $count = 5;
 
push @timers, sub {
my $dt = localtime;
$writer->write("[ $dt ]\n");
 
if (--$count == 0) {
$writer->close();
}
 
return $count > 0;
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.