Created
September 9, 2009 06:23
-
-
Save mala/183515 to your computer and use it in GitHub Desktop.
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
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