• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Anyevent
 

Anyevent

on

  • 548 views

Bulgarian Perl Workshop 2010

Bulgarian Perl Workshop 2010

Statistics

Views

Total Views
548
Views on SlideShare
546
Embed Views
2

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 2

https://duckduckgo.com 2

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Anyevent Anyevent Presentation Transcript

    • Bulgarian Perl Workshop 2010 Event driven programing with  AnyEvent Marian Marinov mm@yuhu.biz   
    • Event Driven programing ● select() ..... and wait ● fork() ..... and wait ● poll/epoll – define..... call when ready ● fork() + wait(WNOHANG)   
    • AnyEvent supports ● EV ● Irssi ● Event ● Qt ● Glib ● Tk ● Event::Lib ● Own pure perl loops ● IO::Async ● POE   
    • 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 (  fh   => $fh,  poll => r,  cb   => sub { $result_ready­>send; }  );  $result_ready­>recv;       
    • 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.   
    • 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   
    • 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)