Skip to content

Instantly share code, notes, and snippets.

@skaurus
Last active October 19, 2018 15:20
Show Gist options
  • Save skaurus/511abe1bda77ecd73a958da8ef9e5a32 to your computer and use it in GitHub Desktop.
Save skaurus/511abe1bda77ecd73a958da8ef9e5a32 to your computer and use it in GitHub Desktop.

Both files in the same folder; all libs installed to local subfolder (using carton/cpanm).

Run like that:

/usr/bin/prove -mrv -I ./local/lib/perl5 test.t

$resolves is equal 0 instead of 2.

use strict;
use warnings;
use FindBin qw/$RealBin/;
use lib $RealBin . '/local/lib/perl5', $RealBin;
use Test::Mojo;
my $t = Test::Mojo->new('TestApp');
$t->get_ok('/')->status_is(200)->content_is('2');
#!/usr/local/bin/perl
package TestApp;
use Mojolicious::Lite;
use Mojo::Promise;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
get '/' => sub {
my $c = shift;
my $resolves = 0;
my $mojo = $ua->get_p('mojolicious.org');
my $cpan = $ua->get_p('cpan.org');
Mojo::Promise->all($mojo, $cpan)->then(sub {
my ($mojo, $cpan) = @_;
$resolves++;
say "resolve cb is called";
# say $mojo->[0]->result->dom->at('title')->text;
# say $cpan->[0]->result->dom->at('title')->text;
})->wait;
say "resolves: $resolves";
$c->render(text => $resolves);
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment