Skip to content

Instantly share code, notes, and snippets.

@renatocron
Created October 31, 2019 14:01
Show Gist options
  • Save renatocron/2c9e64c0dfffeaea9863b01af50830b2 to your computer and use it in GitHub Desktop.
Save renatocron/2c9e64c0dfffeaea9863b01af50830b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use common::sense;
use DDP;
use Mojo::Promise;
use Mojo::IOLoop::Subprocess;
my $subprocess = Mojo::IOLoop::Subprocess->new;
$subprocess->run(
sub {
my $subprocess = shift;
use DDP;
my $new_ioloop = Mojo::IOLoop->new;
my @promises = map {
my $p = Mojo::Promise->new()->ioloop($new_ioloop);
$p->then(
sub {
print STDERR "p is running\n\n";
Mojo::IOLoop->timer(
2 => sub {
$p->('Lucky!');
}
);
}
)->catch(sub { use DDP; p \@_; });
$p;
} (1 .. 10);
#$new_ioloop->one_tick;
print STDERR "->wait\n\n";
Mojo::Promise->all(@promises)->wait();
print STDERR "not today!\n";
return 'a';
},
sub {
use DDP;
p \@_;
}
);
$subprocess->ioloop->start unless $subprocess->ioloop->is_running;
@renatocron
Copy link
Author

it prints '->wait
` but never reach "p is running" nor "not today"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment