SlideShare a Scribd company logo
ASYNCHRONOUS
PROGRAMMING
    FTW!
    (SAWYER X)
DOES THIS SOUND FAMILIAR?
               "Hi"
            "Hi, dad"
         "Got a minute?"
              "Yes"
     "I'm looking for a movie
        Where do I start?"
    "Go to the cinema website"
      "What's the address?"
 "www.whatchamacallit.whatever"
          "Just a sec..."
...
...
...
...
"Well?"
"Ah! It loaded! What now?"
  "Click on new movies"
         "OK..."
           ........
         "Well?"
        "Loading"
    *sounds of clicks*
"OK, now what?"
      "Find a movie you want"
            "Then what?"
"Click on it, you'll have instructions"
        * eternity passes by *
             "WELL?!?"
     "Just a sec... it's loading..."
          /me shoots myself
ILLUSTRATED
          (USING WWW::MECHANIZE)
$eh>e(cnm_r)
 mc­gt$ieaul;
i  mc­sces){
 f($eh>ucs  
  $eh>lc(NwMve';
   mc­cik'e ois)
  i  mc­sces){
   f($eh>ucs  
    m mve  mc­fn_nus..
     y@ois=$eh>idipt(.)
  }
   
}
LET'S TRY THIS AGAIN...
                 "Hi"
               "Hi, dad"
            "Got a minute?"
                 "Yes"
        "I'm looking for a movie
           What should I do?"
"Go to this website, click on new movies
  Then pick a movie, and click on it"
             "Thank you"
           "You're welcome"
GREAT SUCCESS!
CALLBACKS
        Reference to a code
        Passed as an argument
        Can be called by some other code
sbtysmtig{
 u r_oehn 
  m ipt  hf;
   y$nu =sit
  m c    hf;
   y$b  =sit
  m rsl  oeoeain$nu)
   y$eut=sm_prto(ipt;

  i  rsl­{sau' q'K  
   f($eut>'tts}e O'){
    $b> rsl­{cnet})
     c­($eut>'otn' ;
  }
   
}

tysmtig sm admipt,sb{
 r_oehn("oerno nu" u 
  m cnet=sit
   y$otn  hf;
  sy"ucsflrqetsy cnet"
   a Scesu eus as$otn!;
})
  ;
ILLUSTRATED, ASYNC
          (USING WWW::MECHANIZE)
$eh>e($ieaul u 
 mc­gt cnm_r,sb{
  $eh>lc('e ois,sb{
   mc­cik NwMve' u 
    $eh>idipt(.. u  y@ois=@  
     mc­fn_nus .,sb{m mve  _})
  })
    ;
})
  ;
WHY IS THIS USEFUL?
Allow others to decide if something is good or not
m jn  uo>e(
 y$uo=Jn­nw
  hss >[w11112222]
   ot = q<... ...>,
  cek >{
   hcs= 
    Fig= 
     Pn >{
      o_ucs >sb{
       nsces= u 
        m  jn,$ot dt   _
         y($uo hs,$aa)=@;
        m  i,$os ag)=$uo>nlz_igrsl(
         y($p ls,$v   jn­aayepn_eut
          $aa>'ter}
           dt­{sdr',
        )
         ;

        $ef>e_ot hs,$v ;
         sl­sths($ot ag)
      }
       ,

      o_al= u 
       nfi >sb{
        m  jn,$ot)=@;
         y($uo hs   _

        $ef>eeehs(hs)
         sl­dlt_ot$ot;
      }
       ,
    }
     
  }
   
);
WHY IS THIS USEFUL?
Allow others to decide if something is good or not
Allow easy stepping
Algorithm::Diff::Callback
ueAgrtm:if:alakq<ifary ifhse>
 s loih:Df:Clbc wdf_rasdf_ahs;

df_ras
 ifary(
  odfml_ebr,
   @l_aiymmes
  nwfml_ebr,
   @e_aiymmes
  sb{pit'ap oha bu ,sit}
   u  rn Hpyt eraot' hf ,
  sb{pit'or oha bu ,sit}
   u  rn Sryt eraot' hf ,
);

df_ahs
 ifhse(
  oddtis
   %l_eal,
  nwdtis
   %e_eal,
  sb{sy'ot'  hf ,
   u  a Ls , sit}
  sb{sy'and' hf ,
   u  a Gie ,sit}
  sb{
   u 
    m  ky bfr,$fe   _
     y($e,$eoe atr)=@;
    sy"kycagdfo bfr o$fe"
     a $e hne rm$eoet atr;
  }
   ,
);
WHY IS THIS USEFUL?
Allow others to decide if something is good or not
Allow easy stepping
Allow control by other process (a type of IOC)
Allow asynchronous code
THE EVENT LOOP
Create loop
Register events
Run them
Let the user keep registering new events
m eet  ..;
 y%vns=(.)

wie(){
 hl 1 
  frahm eet(ky eet  
   oec y$vn  es%vns){
    $vn­(;
     eet>)
  }
   
}
m eet;%vns=(.)
 y%vns eet  ..;

wie(){
 hl 1 
  frahm eet(ky eet  
   oec y$vn  es%vns){
    $vn­(;
     eet>)
  }
   
}

wie(){
 hl 1 
  frahm eet(ky eet  
   oec y$vn  es%vns){
    i  eet{eet{tm' =tm  
     f($vns$vn}'ie}< ie){
      $vns$vn}'oe}>)
       eet{eet{cd'­(;
    }
     
  }
   
}

sbadeet{
 u d_vn 
  m  tm,$oe)=@;
   y($ie cd   _
  $vns$d{tm'  tm;
   eet{i}'ie}=$ie
  $vns$d{cd'  cd;
   eet{i}'oe}=$oe
  $d+
   i+;
}
EVENT TYPES
Timers (one-time, recurring, sleep replacement)
I/O (input output, including networking)
FUCK TALK
LET'S GO PROGRAMMING
IO::ASYNC
Loop interface: IO::Async::Loop
You can connect to hosts using it
You can add listeners to it (handles, sockets, etc.)
Explicitly call "run" when ready
ueI:Ayc:tem
 s O:sn:Sra;
ueI:Ayc:op
 s O:sn:Lo;
 
m lo  O:sn:Lo­nw
 y$op=I:Ayc:op>e;

$op>onc(
 lo­cnet
  hs   = sm.te.ot,
   ot   >"oeohrhs"
  srie = 24,
   evc  >135
  sctp = sra'
   okye >'tem,
  
  o_tem= u  . ,
   nsra >sb{..}
  
  o_eov_ro >sb{
   nrsleerr= u 
    de"antrsle­$[1"
     i Cno eov  _­]
  }
   ,

  o_onc_ro >sb{
   ncneterr= u 
    de"antcnet­$[]fie _­]
     i Cno onc  _0 ald$[1"
  }
   ,
);

$op>u;
 lo­rn
o_tem= u 
 nsra >sb{
  m  sra   _
   y($tem)=@;

  $tem>ofgr(
   sra­cniue
    o_ed= u 
     nra >sb{
      m  sl,$ufe,$o   _
       y($ef bfrf ef)=@;

      wie {bfrf ~s^.)/){
       hl($$ufe}= /(*n/  
        sy"eevdaln 1;
         a Rcie  ie$"
      }
       

      rtr ;
       eun0
    }
     
  )
   ;

  $tem>rt(A nta iehr';
   sra­wie'niiilln ee)

  $op>d(sra)
   lo­ad$tem;
}
ANOTHER EXAMPLE
$pr MO:sn Me:Ayc:TP­ 
  el­I:Ayc­Nt:sn:HT E'
  I:Ayc>d(m ht  e:Ayc:TP>e ;
   O:sn­ad y$tp=Nt:sn:HT­nw)
  syfrI:Ayc>wi_l(mp{$tp>e(_  )
   a o O:sn­aatal a  ht­gt$)} 
'>ls­fUL.x
   ito­Rstt


         Oh hai parallel HTTP GET!
POE
Loop interface: POE::Kernel
Runs "sessions" (POE::Session)
Each session is a context of events
Each session has an ID and heap
Call events in a current or different session
Explicitly call POE::Kernel->run when ready
POE
uePE #At­nldsPE:enladPE:eso.
 s O;  uoicue O:Kre n O:Ssin

#..dfn alak us(etsie .
  . eieclbcssb nx ld)..

fr(.1){
 o 1.0 
  PE:eso­cet(
   O:Ssin>rae
    iln_tts= 
     niesae >{
      _tr  = &ade_tr,
       sat  >hnlrsat
      iceet= &ade_nrmn,
       nrmn >hnlriceet
      _tp  = &ade_tp
       so   >hnlrso,
    }
     
  )
   ;
}

PE:enl>u(;
 O:Kre­rn)
sbhnlrsat{
 u ade_tr 
 m  kre,$ep ssin)=@[KRE,HA,SSIN]
  y($enl ha,$eso   _ ENL EP ESO ;
 sy"eso ,$eso­I,"hssatd;
  a Ssin" ssin>D  a tre"
 $ep>'on'  ;
  ha­{cut}=0
 $enl>il(iceet)
  kre­yed'nrmn';
}

sbhnlriceet{
 u ade_nrmn 
 m  kre,$ep ssin)=@[KRE,HA,SSIN]
  y($enl ha,$eso   _ ENL EP ESO ;
 sy"eso ,$eso­I,"cutdt ,+$ep>'on';
  a Ssin" ssin>D  one o" +ha­{cut}
 $enl>il(iceet)i ha­{cut}<1;
  kre­yed'nrmn' f$ep>'on'  0
}

sbhnlrso 
 u ade_tp{
 sy"eso ,$[ESO]>D  a tpe"
  a Ssin" _SSIN­I,"hssopd;
}
sbhnlrsat{
 u ade_tr 
 m  kre,$ep ssin)=@[KRE,HA,SSIN]
  y($enl ha,$eso   _ ENL EP ESO ;
 sy"eso ,$eso­I,"hssatd;
  a Ssin" ssin>D  a tre"
 $ep>'on'  ;
  ha­{cut}=0
 $enl>il(iceet)
  kre­yed'nrmn';
}
sbhnlriceet{
 u ade_nrmn 
 m  kre,$ep ssin)=@[KRE,HA,SSIN]
  y($enl ha,$eso   _ ENL EP ESO ;
 sy"eso ,$eso­I,"cutdt ,+$ep>'on';
  a Ssin" ssin>D  one o" +ha­{cut}
 $enl>il(iceet)i ha­{cut}<1;
  kre­yed'nrmn' f$ep>'on'  0
}
sbhnlrso 
 u ade_tp{
 sy"eso ,$[ESO]>D  a tpe.n;
  a Ssin" _SSIN­I,"hssopd"
}
fr(.1){
 o 1.0 
  PE:eso­cet(
   O:Ssin>rae
    iln_tts= 
     niesae >{
      _tr  = &ade_tr,
       sat  >hnlrsat
      iceet= &ade_nrmn,
       nrmn >hnlriceet
      _tp  = &ade_tp
       so   >hnlrso,
    }
     
  )
   ;
}
PE:enl>u(;
 O:Kre­rn)
MORE CONDENSED
uePE
 s O;

fr(.1){
 o 1.0 
  m cut=0
   y$on  ;

  PE:eso­cet(
   O:Ssin>rae
    iln_tts= 
     niesae >{
      _tr  = u 
       sat  >sb{
        sy"eso ,$[ESO]>D  a tre"
         a Ssin" _SSIN­I,"hssatd;
        PE:enl>il(iceet)
         O:Kre­yed'nrmn';
      }
       ,
      iceet= u 
       nrmn >sb{
        PE:enl>il(iceet)i +cut<1;
         O:Kre­yed'nrmn' f+$on  0
        sy"eso ,$[ESO]>D  one o$on"
         a Ssin" _SSIN­I,"cutdt cut;
      }
       ,
      _tp  = u 
       so   >sb{
        sy"eso ,$[ESO]>D  a tpe"
         a Ssin" _SSIN­I,"hssopd;
      }
       ,
    }
     
  )
   ;
}

PE:enl>u(;
 O:Kre­rn)
REFLEX
Written by author of POE
"How POE would be written if I had Moose back then"
Stresses composability, reusability
Includes plenty of additional roles
USING MOOSE
{
  pcaeAp
   akg p;
  ueMoe
   s os;
  etns'elx:ae;
   xed Rfe:Bs'
  ueRfe:Itra;
   s elx:nevl
  ueRfe:Tat:ace wths;
   s elx:ri:Wthd'ace'
 
  wthstce >(
   ace ikr= 
    ia = Rfe:Itra'
     s  >'elx:nevl,
    stp=  nevl= ,at_eet=  ,
     eu >{itra >1 uorpa >1}
  )
   ;
 
  sbo_ikrtc 
   u ntce_ik{
    sy'ika ,saa(oatm) ..;
     a tc t' clrlclie,'.'
  }
   
}
 
ei p­nw)>u_l(;
 xtAp>e(­rnal)
COMPLEX? TRY THIS...
ueRfe:Itra;
 s elx:nevl
 
m t=Rfe:Itra­nw
 y$  elx:nevl>e(
  itra  = ,
   nevl  >1
  at_eet= ,
   uorpa >1
  o_ik  = u  a tmrtce'}
   ntc   >sb{sy'ie ikd ,
);
 
$­rnal)
 t>u_l(;
ANYEVENT
AnyEvent is very thin and very fast
Was written to support as many loops as possible
... that conform to the author's rules of compatibility
Does not use a loop handler, simply runs
Does use conditional variables
Has AE for faster performance
ueAyvn;
 s nEet
m cut=0
 y$on  ;
m c  =Ayvn­cnvr
 y$v   nEet>oda;
m t  =Ayvn­tmr
 y$    nEet>ie(
  atr  >2
   fe  = ,
  itra >06
   nevl= .,
  c    >sb{
   b   = u 
    sy'h iei o:' nEet>o;
     a Tetm snw ,Ayvn­nw
    +$on =1 n c­sn;
     +cut= 0ad$v>ed
  }
   ,
);

$v>ev
 c­rc;
m w w=Ayvn­i(
 y$;$  nEet>o
  f  >SDN
   h = *TI,
  pl >''
   ol= r,
  c  >sb{
   b = u 
    cop(m ipt= ;
     hm  y$nu  )
    sy"ed ipt;
     a ra:$nu"
    udf$;
     ne w
  }
   ,
);
USAGES OF ASYNCHRONOUS CODE
     GUI
     Services (HTTP/SMTP/etc.)
     Performance
     Off-loading tasks
THANK YOU

More Related Content

What's hot

The Wolf
The Wolf The Wolf
The Wolf
Jon David Leslie
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
Wes Oldenbeuving
 
CS50 Lecture2
CS50 Lecture2CS50 Lecture2
CS50 Lecture2
昀 李
 
Day2
Day2Day2
Mahabhara katha
Mahabhara kathaMahabhara katha
Mahabhara kathamianagpur
 
CS50 Lecture1
CS50 Lecture1CS50 Lecture1
CS50 Lecture1
昀 李
 
“Entschuldigung, 
 das weiß ich leider nicht.”
“Entschuldigung, 
 das weiß ich leider nicht.”“Entschuldigung, 
 das weiß ich leider nicht.”
“Entschuldigung, 
 das weiß ich leider nicht.”
Andreas Kwiatkowski
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
Shoichi Matsuda
 
01 linux basics
01 linux basics01 linux basics
01 linux basics
Robson Levi
 
Making sense of big data
Making sense of big dataMaking sense of big data
Making sense of big data
Charlie Hull
 
Big Data LDN 2016: Making Sense of Big Data with Open Source Search
Big Data LDN 2016: Making Sense of Big Data with Open Source SearchBig Data LDN 2016: Making Sense of Big Data with Open Source Search
Big Data LDN 2016: Making Sense of Big Data with Open Source Search
Matt Stubbs
 

What's hot (12)

The Wolf
The Wolf The Wolf
The Wolf
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Adventure time
Adventure timeAdventure time
Adventure time
 
CS50 Lecture2
CS50 Lecture2CS50 Lecture2
CS50 Lecture2
 
Day2
Day2Day2
Day2
 
Mahabhara katha
Mahabhara kathaMahabhara katha
Mahabhara katha
 
CS50 Lecture1
CS50 Lecture1CS50 Lecture1
CS50 Lecture1
 
“Entschuldigung, 
 das weiß ich leider nicht.”
“Entschuldigung, 
 das weiß ich leider nicht.”“Entschuldigung, 
 das weiß ich leider nicht.”
“Entschuldigung, 
 das weiß ich leider nicht.”
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
 
01 linux basics
01 linux basics01 linux basics
01 linux basics
 
Making sense of big data
Making sense of big dataMaking sense of big data
Making sense of big data
 
Big Data LDN 2016: Making Sense of Big Data with Open Source Search
Big Data LDN 2016: Making Sense of Big Data with Open Source SearchBig Data LDN 2016: Making Sense of Big Data with Open Source Search
Big Data LDN 2016: Making Sense of Big Data with Open Source Search
 

Similar to Asynchronous programming FTW!

Automated tests - facts and myths
Automated tests - facts and mythsAutomated tests - facts and myths
Automated tests - facts and myths
Wojciech Sznapka
 
Presenting Seq for Node.js
Presenting Seq for Node.jsPresenting Seq for Node.js
Presenting Seq for Node.js
Douglas Muth
 
Javascript: The Important Bits
Javascript: The Important BitsJavascript: The Important Bits
Javascript: The Important Bits
Zumba Fitness - Technology Team
 
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
Johannes Hoppe
 
TicketBEKA? Ticket booking
TicketBEKA? Ticket bookingTicketBEKA? Ticket booking
TicketBEKA? Ticket booking
Likhith Pujari
 
Front End Dependency Management at CascadiaJS
Front End Dependency Management at CascadiaJSFront End Dependency Management at CascadiaJS
Front End Dependency Management at CascadiaJS
Joe Sepi
 

Similar to Asynchronous programming FTW! (6)

Automated tests - facts and myths
Automated tests - facts and mythsAutomated tests - facts and myths
Automated tests - facts and myths
 
Presenting Seq for Node.js
Presenting Seq for Node.jsPresenting Seq for Node.js
Presenting Seq for Node.js
 
Javascript: The Important Bits
Javascript: The Important BitsJavascript: The Important Bits
Javascript: The Important Bits
 
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
 
TicketBEKA? Ticket booking
TicketBEKA? Ticket bookingTicketBEKA? Ticket booking
TicketBEKA? Ticket booking
 
Front End Dependency Management at CascadiaJS
Front End Dependency Management at CascadiaJSFront End Dependency Management at CascadiaJS
Front End Dependency Management at CascadiaJS
 

More from xSawyer

do_this and die();
do_this and die();do_this and die();
do_this and die();
xSawyer
 
XS Fun
XS FunXS Fun
XS Fun
xSawyer
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
xSawyer
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
xSawyer
 
Our local state, my, my - Understanding Perl variables
Our local state, my, my - Understanding Perl variablesOur local state, my, my - Understanding Perl variables
Our local state, my, my - Understanding Perl variables
xSawyer
 
Your first website in under a minute with Dancer
Your first website in under a minute with DancerYour first website in under a minute with Dancer
Your first website in under a minute with Dancer
xSawyer
 
Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)
xSawyer
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)
xSawyer
 
Perl Dancer for Python programmers
Perl Dancer for Python programmersPerl Dancer for Python programmers
Perl Dancer for Python programmers
xSawyer
 
When Perl Met Android (YAPC::EU 2010)
When Perl Met Android (YAPC::EU 2010)When Perl Met Android (YAPC::EU 2010)
When Perl Met Android (YAPC::EU 2010)
xSawyer
 
Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)
xSawyer
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systems
xSawyer
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
xSawyer
 
Red Flags in Programming
Red Flags in ProgrammingRed Flags in Programming
Red Flags in Programming
xSawyer
 

More from xSawyer (14)

do_this and die();
do_this and die();do_this and die();
do_this and die();
 
XS Fun
XS FunXS Fun
XS Fun
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
 
Our local state, my, my - Understanding Perl variables
Our local state, my, my - Understanding Perl variablesOur local state, my, my - Understanding Perl variables
Our local state, my, my - Understanding Perl variables
 
Your first website in under a minute with Dancer
Your first website in under a minute with DancerYour first website in under a minute with Dancer
Your first website in under a minute with Dancer
 
Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)
 
Perl Dancer for Python programmers
Perl Dancer for Python programmersPerl Dancer for Python programmers
Perl Dancer for Python programmers
 
When Perl Met Android (YAPC::EU 2010)
When Perl Met Android (YAPC::EU 2010)When Perl Met Android (YAPC::EU 2010)
When Perl Met Android (YAPC::EU 2010)
 
Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systems
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
 
Red Flags in Programming
Red Flags in ProgrammingRed Flags in Programming
Red Flags in Programming
 

Recently uploaded

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 

Recently uploaded (20)

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 

Asynchronous programming FTW!

  • 1. ASYNCHRONOUS PROGRAMMING FTW! (SAWYER X)
  • 2. DOES THIS SOUND FAMILIAR? "Hi" "Hi, dad" "Got a minute?" "Yes" "I'm looking for a movie Where do I start?" "Go to the cinema website" "What's the address?" "www.whatchamacallit.whatever" "Just a sec..."
  • 4. "Well?" "Ah! It loaded! What now?" "Click on new movies" "OK..." ........ "Well?" "Loading" *sounds of clicks*
  • 5. "OK, now what?" "Find a movie you want" "Then what?" "Click on it, you'll have instructions" * eternity passes by * "WELL?!?" "Just a sec... it's loading..." /me shoots myself
  • 6. ILLUSTRATED (USING WWW::MECHANIZE) $eh>e(cnm_r) mc­gt$ieaul; i  mc­sces){ f($eh>ucs     $eh>lc(NwMve';   mc­cik'e ois)   i  mc­sces){   f($eh>ucs       m mve  mc­fn_nus..     y@ois=$eh>idipt(.)   }    }
  • 7. LET'S TRY THIS AGAIN... "Hi" "Hi, dad" "Got a minute?" "Yes" "I'm looking for a movie What should I do?" "Go to this website, click on new movies Then pick a movie, and click on it" "Thank you" "You're welcome"
  • 9. CALLBACKS Reference to a code Passed as an argument Can be called by some other code sbtysmtig{ u r_oehn    m ipt  hf;   y$nu =sit   m c    hf;   y$b  =sit   m rsl  oeoeain$nu)   y$eut=sm_prto(ipt;   i  rsl­{sau' q'K     f($eut>'tts}e O'){     $b> rsl­{cnet})     c­($eut>'otn' ;   }    } tysmtig sm admipt,sb{ r_oehn("oerno nu" u    m cnet=sit   y$otn  hf;   sy"ucsflrqetsy cnet"   a Scesu eus as$otn!; })  ;
  • 10. ILLUSTRATED, ASYNC (USING WWW::MECHANIZE) $eh>e($ieaul u  mc­gt cnm_r,sb{   $eh>lc('e ois,sb{   mc­cik NwMve' u      $eh>idipt(.. u  y@ois=@       mc­fn_nus .,sb{m mve  _})   })    ; })  ;
  • 11. WHY IS THIS USEFUL? Allow others to decide if something is good or not
  • 12. m jn  uo>e( y$uo=Jn­nw   hss >[w11112222]   ot = q<... ...>,   cek >{   hcs=      Fig=      Pn >{       o_ucs >sb{       nsces= u          m  jn,$ot dt   _         y($uo hs,$aa)=@;         m  i,$os ag)=$uo>nlz_igrsl(         y($p ls,$v   jn­aayepn_eut           $aa>'ter}           dt­{sdr',         )         ;         $ef>e_ot hs,$v ;         sl­sths($ot ag)       }       ,       o_al= u        nfi >sb{         m  jn,$ot)=@;         y($uo hs   _         $ef>eeehs(hs)         sl­dlt_ot$ot;       }       ,     }        }    );
  • 13. WHY IS THIS USEFUL? Allow others to decide if something is good or not Allow easy stepping
  • 14. Algorithm::Diff::Callback ueAgrtm:if:alakq<ifary ifhse> s loih:Df:Clbc wdf_rasdf_ahs; df_ras ifary(   odfml_ebr,   @l_aiymmes   nwfml_ebr,   @e_aiymmes   sb{pit'ap oha bu ,sit}   u  rn Hpyt eraot' hf ,   sb{pit'or oha bu ,sit}   u  rn Sryt eraot' hf , ); df_ahs ifhse(   oddtis   %l_eal,   nwdtis   %e_eal,   sb{sy'ot'  hf ,   u  a Ls , sit}   sb{sy'and' hf ,   u  a Gie ,sit}   sb{   u      m  ky bfr,$fe   _     y($e,$eoe atr)=@;     sy"kycagdfo bfr o$fe"     a $e hne rm$eoet atr;   }   , );
  • 15. WHY IS THIS USEFUL? Allow others to decide if something is good or not Allow easy stepping Allow control by other process (a type of IOC) Allow asynchronous code
  • 16. THE EVENT LOOP Create loop Register events Run them Let the user keep registering new events
  • 17. m eet  ..; y%vns=(.) wie(){ hl 1    frahm eet(ky eet     oec y$vn  es%vns){     $vn­(;     eet>)   }    }
  • 18. m eet;%vns=(.) y%vns eet  ..; wie(){ hl 1    frahm eet(ky eet     oec y$vn  es%vns){     $vn­(;     eet>)   }    } wie(){ hl 1    frahm eet(ky eet     oec y$vn  es%vns){     i  eet{eet{tm' =tm       f($vns$vn}'ie}< ie){       $vns$vn}'oe}>)       eet{eet{cd'­(;     }        }    } sbadeet{ u d_vn    m  tm,$oe)=@;   y($ie cd   _   $vns$d{tm'  tm;   eet{i}'ie}=$ie   $vns$d{cd'  cd;   eet{i}'oe}=$oe   $d+   i+; }
  • 19. EVENT TYPES Timers (one-time, recurring, sleep replacement) I/O (input output, including networking)
  • 20. FUCK TALK LET'S GO PROGRAMMING
  • 21. IO::ASYNC Loop interface: IO::Async::Loop You can connect to hosts using it You can add listeners to it (handles, sockets, etc.) Explicitly call "run" when ready
  • 22. ueI:Ayc:tem s O:sn:Sra; ueI:Ayc:op s O:sn:Lo;   m lo  O:sn:Lo­nw y$op=I:Ayc:op>e; $op>onc( lo­cnet   hs   = sm.te.ot,   ot   >"oeohrhs"   srie = 24,   evc  >135   sctp = sra'   okye >'tem,      o_tem= u  . ,   nsra >sb{..}      o_eov_ro >sb{   nrsleerr= u      de"antrsle­$[1"     i Cno eov  _­]   }   ,   o_onc_ro >sb{   ncneterr= u      de"antcnet­$[]fie _­]     i Cno onc  _0 ald$[1"   }   , ); $op>u; lo­rn
  • 23. o_tem= u  nsra >sb{   m  sra   _   y($tem)=@;   $tem>ofgr(   sra­cniue     o_ed= u      nra >sb{       m  sl,$ufe,$o   _       y($ef bfrf ef)=@;       wie {bfrf ~s^.)/){       hl($$ufe}= /(*n/           sy"eevdaln 1;         a Rcie  ie$"       }              rtr ;       eun0     }        )   ;   $tem>rt(A nta iehr';   sra­wie'niiilln ee)   $op>d(sra)   lo­ad$tem; }
  • 24. ANOTHER EXAMPLE $pr MO:sn Me:Ayc:TP­   el­I:Ayc­Nt:sn:HT E'   I:Ayc>d(m ht  e:Ayc:TP>e ;   O:sn­ad y$tp=Nt:sn:HT­nw)   syfrI:Ayc>wi_l(mp{$tp>e(_  )   a o O:sn­aatal a  ht­gt$)}  '>ls­fUL.x   ito­Rstt Oh hai parallel HTTP GET!
  • 25. POE Loop interface: POE::Kernel Runs "sessions" (POE::Session) Each session is a context of events Each session has an ID and heap Call events in a current or different session Explicitly call POE::Kernel->run when ready
  • 26. POE uePE #At­nldsPE:enladPE:eso. s O;  uoicue O:Kre n O:Ssin #..dfn alak us(etsie .  . eieclbcssb nx ld).. fr(.1){ o 1.0    PE:eso­cet(   O:Ssin>rae     iln_tts=      niesae >{       _tr  = &ade_tr,       sat  >hnlrsat       iceet= &ade_nrmn,       nrmn >hnlriceet       _tp  = &ade_tp       so   >hnlrso,     }        )   ; } PE:enl>u(; O:Kre­rn)
  • 27. sbhnlrsat{ u ade_tr   m  kre,$ep ssin)=@[KRE,HA,SSIN]  y($enl ha,$eso   _ ENL EP ESO ;  sy"eso ,$eso­I,"hssatd;  a Ssin" ssin>D  a tre"  $ep>'on'  ;  ha­{cut}=0  $enl>il(iceet)  kre­yed'nrmn'; } sbhnlriceet{ u ade_nrmn   m  kre,$ep ssin)=@[KRE,HA,SSIN]  y($enl ha,$eso   _ ENL EP ESO ;  sy"eso ,$eso­I,"cutdt ,+$ep>'on';  a Ssin" ssin>D  one o" +ha­{cut}  $enl>il(iceet)i ha­{cut}<1;  kre­yed'nrmn' f$ep>'on'  0 } sbhnlrso  u ade_tp{  sy"eso ,$[ESO]>D  a tpe"  a Ssin" _SSIN­I,"hssopd; }
  • 28. sbhnlrsat{ u ade_tr   m  kre,$ep ssin)=@[KRE,HA,SSIN]  y($enl ha,$eso   _ ENL EP ESO ;  sy"eso ,$eso­I,"hssatd;  a Ssin" ssin>D  a tre"  $ep>'on'  ;  ha­{cut}=0  $enl>il(iceet)  kre­yed'nrmn'; } sbhnlriceet{ u ade_nrmn   m  kre,$ep ssin)=@[KRE,HA,SSIN]  y($enl ha,$eso   _ ENL EP ESO ;  sy"eso ,$eso­I,"cutdt ,+$ep>'on';  a Ssin" ssin>D  one o" +ha­{cut}  $enl>il(iceet)i ha­{cut}<1;  kre­yed'nrmn' f$ep>'on'  0 } sbhnlrso  u ade_tp{  sy"eso ,$[ESO]>D  a tpe.n;  a Ssin" _SSIN­I,"hssopd" } fr(.1){ o 1.0    PE:eso­cet(   O:Ssin>rae     iln_tts=      niesae >{       _tr  = &ade_tr,       sat  >hnlrsat       iceet= &ade_nrmn,       nrmn >hnlriceet       _tp  = &ade_tp       so   >hnlrso,     }        )   ; } PE:enl>u(; O:Kre­rn)
  • 29. MORE CONDENSED uePE s O; fr(.1){ o 1.0    m cut=0   y$on  ;   PE:eso­cet(   O:Ssin>rae     iln_tts=      niesae >{       _tr  = u        sat  >sb{         sy"eso ,$[ESO]>D  a tre"         a Ssin" _SSIN­I,"hssatd;         PE:enl>il(iceet)         O:Kre­yed'nrmn';       }       ,       iceet= u        nrmn >sb{         PE:enl>il(iceet)i +cut<1;         O:Kre­yed'nrmn' f+$on  0         sy"eso ,$[ESO]>D  one o$on"         a Ssin" _SSIN­I,"cutdt cut;       }       ,       _tp  = u        so   >sb{         sy"eso ,$[ESO]>D  a tpe"         a Ssin" _SSIN­I,"hssopd;       }       ,     }        )   ; } PE:enl>u(; O:Kre­rn)
  • 30. REFLEX Written by author of POE "How POE would be written if I had Moose back then" Stresses composability, reusability Includes plenty of additional roles
  • 31. USING MOOSE {   pcaeAp   akg p;   ueMoe   s os;   etns'elx:ae;   xed Rfe:Bs'   ueRfe:Itra;   s elx:nevl   ueRfe:Tat:ace wths;   s elx:ri:Wthd'ace'     wthstce >(   ace ikr=      ia = Rfe:Itra'     s  >'elx:nevl,     stp=  nevl= ,at_eet=  ,     eu >{itra >1 uorpa >1}   )   ;     sbo_ikrtc    u ntce_ik{     sy'ika ,saa(oatm) ..;     a tc t' clrlclie,'.'   }    }   ei p­nw)>u_l(; xtAp>e(­rnal)
  • 32. COMPLEX? TRY THIS... ueRfe:Itra; s elx:nevl   m t=Rfe:Itra­nw y$  elx:nevl>e(   itra  = ,   nevl  >1   at_eet= ,   uorpa >1   o_ik  = u  a tmrtce'}   ntc   >sb{sy'ie ikd , );   $­rnal) t>u_l(;
  • 33. ANYEVENT AnyEvent is very thin and very fast Was written to support as many loops as possible ... that conform to the author's rules of compatibility Does not use a loop handler, simply runs Does use conditional variables Has AE for faster performance
  • 34. ueAyvn; s nEet m cut=0 y$on  ; m c  =Ayvn­cnvr y$v   nEet>oda; m t  =Ayvn­tmr y$    nEet>ie(   atr  >2   fe  = ,   itra >06   nevl= .,   c    >sb{   b   = u      sy'h iei o:' nEet>o;     a Tetm snw ,Ayvn­nw     +$on =1 n c­sn;     +cut= 0ad$v>ed   }   , ); $v>ev c­rc;
  • 35. m w w=Ayvn­i( y$;$  nEet>o   f  >SDN   h = *TI,   pl >''   ol= r,   c  >sb{   b = u      cop(m ipt= ;     hm  y$nu  )     sy"ed ipt;     a ra:$nu"     udf$;     ne w   }   , );
  • 36. USAGES OF ASYNCHRONOUS CODE GUI Services (HTTP/SMTP/etc.) Performance Off-loading tasks