Skip to content

Instantly share code, notes, and snippets.

@zigorou
Last active December 13, 2015 22:49
Show Gist options
  • Save zigorou/4987640 to your computer and use it in GitHub Desktop.
Save zigorou/4987640 to your computer and use it in GitHub Desktop.
Twiggy::Prefork の練習
#!/usr/bin/env perl
use strict;
use warnings;
use Coro;
use AnyEvent;
use AnyEvent::Log;
$AnyEvent::Log::FILTER->level("debug");
my $channel = Coro::Channel->new(100);
async {
while (1) {
my $q = $channel->get;
# works
AE::log( debug => sprintf("channel->get (pid: %s)", $$) );
$q->[0]->end;
AE::log( debug => sprintf("guard->end (pid: %s)", $$) );
}
};
sub {
my $env = shift;
AE::log( debug => sprintf("env (pid: %s)", $$) );
my $cv = AE::cv;
async {
AE::log( debug => sprintf("guard->begin (pid: %s)", $$) );
$env->{"psgix.exit_guard"}->begin;
AE::log( debug => sprintf("channel->put (pid: %s)", $$) );
$channel->put([ $env->{"psgix.exit_guard"} ]);
AE::log( debug => sprintf("cv->send (pid: %s)", $$) );
$cv->send;
};
return sub {
my $start_response = shift;
AE::log( debug => sprintf("start_response (pid: %s)", $$) );
$cv->cb(sub {
AE::log( debug => sprintf("start_response write (pid: %s)", $$) );
$start_response->([200, ["Content-Type" => "text/plain"], ["OK"]]);
});
};
};
#!/usr/bin/env perl
use strict;
use warnings;
use Coro;
use AnyEvent;
use AnyEvent::Log;
$AnyEvent::Log::FILTER->level("debug");
my $channel = Coro::Channel->new(100);
async {
while (1) {
my $q = $channel->get;
# works
AE::log( debug => sprintf("channel->get (pid: %s)", $$) );
$q->[0]->end;
AE::log( debug => sprintf("guard->end (pid: %s)", $$) );
}
};
async {
AE::log( debug => sprintf("xxx (pid: %s)", $$) );
};
sub {
my $env = shift;
AE::log( debug => sprintf("env (pid: %s)", $$) );
my $cv = AE::cv;
async {
AE::log( debug => sprintf("before (pid: %s)", $$) );
};
async {
AE::log( debug => sprintf("guard->begin (pid: %s)", $$) );
$env->{"psgix.exit_guard"}->begin;
AE::log( debug => sprintf("channel->put (pid: %s)", $$) );
$channel->put([ $env->{"psgix.exit_guard"} ]);
AE::log( debug => sprintf("cv->send (pid: %s)", $$) );
$cv->send;
};
async {
AE::log( debug => sprintf("after (pid: %s)", $$) );
};
return sub {
my $start_response = shift;
AE::log( debug => sprintf("start_response (pid: %s)", $$) );
$cv->cb(sub {
AE::log( debug => sprintf("start_response write (pid: %s)", $$) );
$start_response->([200, ["Content-Type" => "text/plain"], ["OK"]]);
# AE::log( debug => sprintf("start_response write end (pid: %s)", $$) );
});
};
};

Twiggy::Prefork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment