ElasticSearch::AnyEvent pre-release available on github
I've just pushed ElasticSearch::AnyEvent - this brings async requests to the Perl ElasticSearch client. It is still lacking proper documentation and any tests, which will soon follow.
It is available on the anyevent branch on github
This is my first foray into async programming in Perl, so I'd appreciate feedback on the API and code.
Briefly, it can be used as follows:
use ElasticSearch::AnyEvent();
my $es = ElasticSearch::AnyEvent->new(servers=>'127.0.0.1:9200');
# Blocking
my $cv = $es->current_server;
print $cv->recv;
# or
print $es->current_server->recv
# Callback
my $cv = $es->current_server;
$es->cb(sub {
my $result = shift || die $@;
....
});
# Context
my $cv = $es->current_server;
undef $cv; # cancels
$es->refresh_servers; # fire-and-forget
start_event_loop();
{
my $cv1 = $es->foo;
my $cv2 = $es->foo;
$cv2->cb(...);
}
# $cv1 is cancelled
# $cv2 is backgrounded / fire-and-forget
# Multitask:
$es->multi_task(
action => 'index',
pull_queue => sub {
# returns a list of HASHes to be passed to $es->$action(...)
# can return (eg) 1000 at a time
},
on_success => sub { # optional
my ($args,$result) = @_;
...
},
on_error => sub { # optional
my ($error,$args,$queue) = @_;
...
},
)->recv || die "Error";
Did anything come of this?
Yes, we have two async backends:
AnyEvent::HTTP - https://metacpan.org/module/ElasticSearch::Transport::AEHTTP
libcurl - https://metacpan.org/module/ElasticSearch::Transport::AECurl
Just install these modules and use "transport" to choose your backend:
However, Elastic::Model doesn't have async support yet - still working on that.