The shortest and simplest possible asynchronous application.
[ZOOM-Perl-moved-to-github.git] / samples / zoom / trivial-async.pl
1 use ZOOM;
2 @targets = ('z3950.loc.gov:7090/Voyager',
3             'bagel.indexdata.com:210/gils');
4 $o = new ZOOM::Options();
5 $o->option(async => 1);         # asynchronous mode
6 $o->option(count => 1);         # piggyback retrieval count
7 $o->option(preferredRecordSyntax => "usmarc");
8 for ($i = 0; $i < @targets; $i++) {
9     $z[$i] = create ZOOM::Connection($o);
10     $z[$i]->connect($targets[$i]);
11     $r[$i] = $z[$i]->search_pqf("mineral");
12 }
13 while (($i = ZOOM::event(\@z)) != 0) {
14     $ev = $z[$i-1]->last_event();
15     print("connection ", $i-1, ": ", ZOOM::event_str($ev), "\n");
16     if ($ev == ZOOM::Event::ZEND) {
17         $size = $r[$i-1]->size();
18         print "connection ", $i-1, ": $size hits\n";
19         print $r[$i-1]->record(0)->render()
20             if $size > 0;
21     }
22 }