Acme-CPANModulesBundle-Import-MojoliciousAdvent-2018

 view release on metacpan or  search on metacpan

devdata/https_mojolicious.io_blog_2018_12_03_higher-order-promises_  view on Meta::CPAN

    sub { say "None of them worked!" },
    );

$some_promise->wait;
</code></pre>

<h3>None</h3>

<p>A &quot;none&quot; Promise resolves when all of the its Promises are rejected. It&#39;s a trivial case that might be useful somewhere and I created it mostly because Perl 6 has a <a href="https://docs.perl6.org/routine/none">none Junction</a> (whi...

<p>For this very simple example, consider the task to check that no sites are that annoying &quot;404 File Not Found&quot;:</p>

<pre><code>use v5.28;
use utf8;
use strict;
use warnings;
use feature qw(signatures);
no warnings qw(experimental::signatures);

use Mojo::UserAgent;
my $ua = Mojo::UserAgent-&gt;new;

devdata/https_mojolicious.io_blog_2018_12_03_higher-order-promises_  view on Meta::CPAN


my @urls = qw(
  https://www.learning-perl.com/
  https://www.perl.org/
  https://perldoc.perl.org/not_there.pod
  );

my @all_sites = map {
  my $p = $ua-&gt;get_p( $_ );
  $p-&gt;then( sub ( $tx ) {
    $tx-&gt;res-&gt;code == 404 ? $tx-&gt;req-&gt;url : die $tx-&gt;req-&gt;url
    } );
  } @urls;

my $all_promise = Mojo::Promise
  -&gt;with_roles( &#39;+None&#39; )
  -&gt;none( @all_sites )
  -&gt;then(
    sub { say &quot;None of them were 404!&quot; },
    sub { say &quot;At least one was 404: @_!&quot; },
    );

$all_promise-&gt;wait;
</code></pre>

<h2>Conclusion</h2>

<p>It&#39;s easy to make new Promises out of smaller ones to represent complex situations. You can combine the Promises that Mojolicious creates for you with your own handmade Promises to do almost anything you like.</p>

              </section>



( run in 2.253 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )