# ElasticSearch::AnyEvent - async Perl client

**URL:** <https://discuss.elastic.co/t/elasticsearch-anyevent-async-perl-client/3261>\
**Category:** Elasticsearch\
**Created:** [August 26, 2010, 11:57am UTC](https://discuss.elastic.co/t/elasticsearch-anyevent-async-perl-client/3261 "2010-08-26T11:57:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 26, 2010, 11:57am UTC](https://discuss.elastic.co/t/elasticsearch-anyevent-async-perl-client/3261/1 "2010-08-26T11:57:18Z")

</div>

Hi all

For the Perl users out there:

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:

[http://github.com/clintongormley/ElasticSearch.pm/tree/anyevent](http://github.com/clintongormley/ElasticSearch.pm/tree/anyevent)

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";

thanks

Clint

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:20am UTC](https://discuss.elastic.co/t/elasticsearch-anyevent-async-perl-client/3261/2 "2017-07-06T04:20:17Z")

</div>

Closed on July 6, 2017, 4:20am UTC


