Bulgarian Perl Workshop 2010    Event driven programing with              AnyEvent                            Marian Marin...
Event Driven programing    ●   select() ..... and wait    ●   fork() ..... and wait    ●   poll/epoll – define..... call w...
AnyEvent supports    ●   EV                  ●   Irssi    ●   Event               ●   Qt    ●   Glib                ●   Tk...
Log analyzer    Blocking example:        open FD, -|, tail -f messages;        while(<FD>) { xxxxx; }        close FD;    ...
Log analyzer          Non-blocking example:          my $result_ready = AnyEvent->condvar;          my $w = AnyEvent­>io (...
AnyEvent methods    ●   AnyEvent­>io (fh => $fh, poll => "r", cb => sub { ...  });    ●   AnyEvent­>timer (after => $secon...
AnyEvent methods    ●   AnyEvent­>signal (signal => "TERM", cb => sub { ... });    ●   AnyEvent­>child (pid => $pid, cb =>...
How its done    ●   Setup a condition    ●   Write what you want to do (setup a watcher)           –   setup a producer in...
Upcoming SlideShare
Loading in...5
×

Anyevent

349

Published on

Bulgarian Perl Workshop 2010

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
349
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Anyevent

  1. 1. Bulgarian Perl Workshop 2010 Event driven programing with  AnyEvent Marian Marinov mm@yuhu.biz   
  2. 2. Event Driven programing ● select() ..... and wait ● fork() ..... and wait ● poll/epoll – define..... call when ready ● fork() + wait(WNOHANG)   
  3. 3. AnyEvent supports ● EV ● Irssi ● Event ● Qt ● Glib ● Tk ● Event::Lib ● Own pure perl loops ● IO::Async ● POE   
  4. 4. Log analyzer Blocking example: open FD, -|, tail -f messages; while(<FD>) { xxxxx; } close FD;   
  5. 5. Log analyzer Non-blocking example: my $result_ready = AnyEvent->condvar;  my $w = AnyEvent­>io (  fh   => $fh,  poll => r,  cb   => sub { $result_ready­>send; }  );  $result_ready­>recv;       
  6. 6. AnyEvent methods ● AnyEvent­>io (fh => $fh, poll => "r", cb => sub { ...  }); ● AnyEvent­>timer (after => $seconds, cb => sub { ...  }); ● AnyEvent­>timer (after => $seconds, interval =>  $seconds, cb => ... ● AnyEvent­>now;  # prints current event loop time ● AnyEvent­>time; # think Time::HiRes::time or simply  CORE::time.   
  7. 7. AnyEvent methods ● AnyEvent­>signal (signal => "TERM", cb => sub { ... }); ● AnyEvent­>child (pid => $pid, cb => sub { ... }); ● AnyEvent­>idle (cb => sub { ... }); ● AnyEvent­>condvar; # condition state ● $condition­>send; # send signal to the receivers  ● $condition­>recv; # continue from here   
  8. 8. How its done ● Setup a condition ● Write what you want to do (setup a watcher) – setup a producer into the watcher ● Set a stop point (consumer)   
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×