Skip to content

Instantly share code, notes, and snippets.

@mala
Created September 9, 2009 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mala/183515 to your computer and use it in GitHub Desktop.
Save mala/183515 to your computer and use it in GitHub Desktop.
use lib qw(../lib);
use Plack::Loader;
Plack::Loader->load("AnyEvent", port => 8888, host => "127.0.0.1")->run(\&handler);
sub handler {
my ( $env, $start_response ) = @_;
unless ($env->{psgi.async}) {
return [200, [], "Not Supported."]
}
my $writer = $start_response->( 200, [] );
my $stop;
my $coro = async {
while ( !$stop ) {
$chunk = "time is " . time() . "\n";
$writer->write($chunk);
Coro::sleep 1;
}
$writer->write("good bye.");
$writer->close;
};
return sub {
my $reason = shift;
warn sprintf "Stop by %s", $reason;
$stop = 1
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment