Closed xiaoyafeng closed 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();
my @data_queue;
my %handle_opts; $handle_opts{read_size} = $size if defined($size); @@ -163,7 +164,8 @@ }, on_body => sub {
_set_response_headers($response, $_[1]);
$headers_avail->send();
@@ -186,7 +190,15 @@ $headers_avail->recv();
return $self->collect($arg, $response, sub {
it's very clear! Thanks
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