Acme-CPANModulesBundle-Import-MojoliciousAdvent-2017

 view release on metacpan or  search on metacpan

devdata/https_mojolicious.io_blog_2017_12_14_day-14-you-promised-to-call  view on Meta::CPAN


                  <time class="date" datetime="2017-12-14">Dec 14, 2017</time>
                  

              </p>

            </div>

              <div class="post-thumb">
                <!-- theme suggests 1300x500 -->
                <img alt="Two hands with interlocked pinkies, a pinky swear" src="/blog/2017/12/14/day-14-you-promised-to-call/pinky_swear.jpg">
              </div>

            <div class="post-content">

              <section id="section-1">
                  <p>A new feature of <a href="http://mojolicious.org/">Mojolicious</a>, as of <a href="https://metacpan.org/release/SRI/Mojolicious-7.49">7.49</a>, is the implementation of the <a href="https://promisesaplus.com/implementations#in-ot...

              </section>
              <section id="section-2">
                  <h2>Background</h2>

<p>&quot;Normal&quot; Perl code runs synchronously: it does each step it is told to, one at a time, and only that. This is also known as &quot;blocking&quot;, since the program cannot do anything else.</p>

<p>The essence of a non-blocking code framework is that if you are waiting for something, you can register with the framework what to do when that thing happens. It can then do other processing tasks in the meantime. This means you don&#39;t have lot...

<p>Originally this was done just using callbacks, but this lead to what is known as &quot;callback hell&quot;: each callback contains the next callback, at an increasing level of indentation. Even harder to keep track of is if the functions are kept ...

<p>Promises are used to easily add processing steps to a transaction: one can keep adding code for what to do &quot;then&quot; - after a previous stage has finished. Best of all, each &quot;callback&quot; is small and separate, with each one placed i...

<p>First let&#39;s get web pages, one after the other, synchronously. Obviously, that means the code will block anything else while it&#39;s running.</p>

<pre><code># refers to a previously-set-up @urls
sub fetchpages {
  while (my $url = shift @urls) {



( run in 0.535 second using v1.01-cache-2.11-cpan-49f99fa48dc )