Skip to content

Instantly share code, notes, and snippets.

@zigorou
Last active December 13, 2015 22:49

Revisions

  1. zigorou revised this gist Feb 19, 2013. 2 changed files with 105 additions and 0 deletions.
    46 changes: 46 additions & 0 deletions 0.psgi
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/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"]]);
    });
    };
    };
    59 changes: 59 additions & 0 deletions 1.psgi
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    #!/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)", $$) );
    });
    };
    };
  2. zigorou created this gist Feb 19, 2013.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Twiggy::Prefork