ikegami / perl-LWP-Protocol-AnyEvent-http

Event loop friendly HTTP and HTTPS backend for Perl's LWP
http://search.cpan.org/dist/LWP-Protocol-AnyEvent-http/
Creative Commons Zero v1.0 Universal
9 stars 6 forks source link

difference between LPAh and LPCh #10

Closed xiaoyafeng closed 5 years ago

xiaoyafeng commented 5 years ago

Hi ikegami, I've found you maintain this two module in parallel. What difference is between them? As I guess from name, does LPAh use several loop way(including Coro) and LPCh only use Coro thread? Please enlighten me, Thanks

ikegami commented 5 years ago

On Sun, Mar 24, 2019 at 10:39 AM xiaoyafeng notifications@github.com wrote:

Hi ikegami, I've found you maintain this two module in parallel. What difference is between them? As I guess from name, does LPAh use several loop way(including Coro) and LPCh only use Coro thread? Please enlighten me, Thanks

Hi, I wrote LPCh first, then I realized Coro wasn't needed at all, so I wrote LPAh (which uses just AE instead of AE+Coro).

The two are virtually identical. AnyEvent::HTTP does all the hard work for both of them. The only difference is that LPCh uses a Coro channel for synchronization, and LPAh uses AE condvars. Neither uses Coro threads. I've included a diff of the two (minus differences in documentation) below.

Since LPAh has fewer moving parts (no Coro), that's the one I recommend. I kept LPCh around "just in case". But I keep LPCh up to date -- any changes I do are done to both LPAh and LPCh. If I get tired of that, I can always obsolete LPCh by making it use LPAh.

$ diff -u LWP-Protocol-Coro-http/git/lib/LWP/Protocol/Coro/http.pm LWP-Protocol-AnyEvent-http/git/lib/LWP/Protocol/AnyEvent/http.pm --- LWP-Protocol-Coro-http/git/lib/LWP/Protocol/Coro/http.pm 2018-05-13 03:48:32.584619100 -0400 +++ LWP-Protocol-AnyEvent-http/git/lib/LWP/Protocol/AnyEvent/http.pm 2018-05-13 03:47:02.812772300 -0400 @@ -1,13 +1,13 @@

-package LWP::Protocol::Coro::http; +package LWP::Protocol::AnyEvent::http;

use strict; use warnings;

use version; our $VERSION = qv('v1.15.0');

+use AnyEvent qw( ); use AnyEvent::HTTP qw( ); -use Coro::Channel qw( ); use HTTP::Response qw( ); use LWP::Protocol qw( ); use LWP::Protocol::http qw( ); @@ -123,7 +123,8 @@ $response->request($request);

my $headers_avail = AnyEvent->condvar();

@@ -186,7 +190,15 @@ $headers_avail->recv();

return $self->collect($arg, $response, sub {
xiaoyafeng commented 5 years ago

it's very clear! Thanks