Skip to content

Instantly share code, notes, and snippets.

@dougwilson
Created May 31, 2011 07:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dougwilson/608ede892f073a3045f3 to your computer and use it in GitHub Desktop.
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