Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created May 24, 2012 06:57
Show Gist options
  • Select an option

  • Save kazeburo/2779914 to your computer and use it in GitHub Desktop.

Select an option

Save kazeburo/2779914 to your computer and use it in GitHub Desktop.
use Coro;
use Coro::Channel;
use Coro::Timer;
use Plack::Request;
my $queue = Coro::Channel->new(100);
for ( 1..10 ) {
async {
while(1) {
my $req = $queue->get();
my ($path_info, $guard) = @{$req};
Coro::Timer::sleep 3;
warn "finish". $path_info;
$guard->end;
}
};
}
sub {
my $env = shift;
my $req = Plack::Request->new($env);
warn "start". $path_info;
$env->{'psgix.exit_guard'}->begin;
$queue->put([$req->path_info,$env->{'psgix.exit_guard'}]);
[200,['Content-Type'=>'text/plain'],["OK ". $req->path_info ."\n"]];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment