Example counter PSGI app for Twiggy server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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