title: Non-blocking / Asynchronous Execution in Perl
body: <p>Is there a way to implement non-blocking / asynchronous execution (without <a href="http://perldoc.perl.org/functions/fork.html" rel="noreferrer"><code>fork()</code></a>'ing) in Perl?</p>
  <p>I used to be a Python developer for many years... Python has really great 'Twisted' framework that allows to do so (using <a href="http://twistedmatrix.com/documents/current/core/howto/defer.html" rel="noreferrer">DEFERREDs</a>. When I ran search to see if there is anything in Perl to do the same, I came across <a href="http://p3rl.org/POE" rel="noreferrer">POE framework</a> - which seemed &quot;close&quot; enough to what I was searching for. But... after spending some time reading the documentation and &quot;playing&quot; with the code, I came against &quot;the wall&quot; - which is following limitation (from <a href="http://p3rl.org/POE::Session" rel="noreferrer">POE::Session</a> documentation):</p>
  <blockquote>
  <p>Callbacks are not preemptive. As long as one is running, no others will be dispatched. This is known as cooperative multitasking. Each session must cooperate by returning to the central dispatching kernel.</p>
  </blockquote>
  <p>This limitation essentially defeats the purpose of asynchronous/parallel/non-blocking execution - by restricting to only one callback (block of code) executing at any given moment. No other callback can start running while another is already running!</p>
  <p>So... is there any way in Perl to implement multi-tasking (parallel, non-blocking, asynchronous execution of code) without <a href="http://perldoc.perl.org/functions/fork.html" rel="noreferrer"><code>fork()</code></a>'ing - similar to <a href="http://twistedmatrix.com/documents/current/core/howto/defer.html" rel="noreferrer">DEFERREDs</a> in Python?</p>