Skip to content

@dougwilson /counter.psgi secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Example counter PSGI app for Twiggy server
# 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.