Created
September 29, 2021 19:08
-
-
Save tommybutler/7723b4c2628d0e147206b5c53bab7227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $start = scalar localtime; | |
my @records = ( 'some', 'dbi', 'fetchrow', 'hashrefs' ); | |
$promises->{first}->then | |
( | |
sub | |
{ | |
warn 'DONE WITH FIRST PROMISE'; | |
warn 'START: ' . $start; | |
warn 'FINISH: ' . scalar localtime; | |
warn 'KICKING OFF SECOND PROMISE...'; | |
$start = scalar localtime; | |
return $promises->{second}; | |
}, | |
sub | |
{ | |
warn 'FIRST PROMISE FAILURE AFTER INVENTORY EDIT: ' . join "\n", @_; | |
} | |
)->then | |
( | |
sub | |
{ | |
warn 'DONE WITH SECOND PROMISE'; | |
warn 'START: ' . $start; | |
warn 'FINISH: ' . scalar localtime; | |
warn 'KICKING OFF FINAL WRAPUP ACTIONS...'; | |
$start = scalar localtime; | |
return Mojo::Promise->map | |
( | |
{ concurrency => $threads }, | |
sub | |
{ | |
my $record = $_; | |
my $promise = Mojo::Promise->new(); | |
Mojo::IOLoop->subprocess->run | |
( | |
sub { $foo->do_wrapup_work( $record->{id} ) }, | |
sub | |
{ | |
my ( $subproc, $err, $result ) = @_; | |
if ( $err ) | |
{ | |
$promise->reject( $err ) | |
} | |
else | |
{ | |
$promise->resolve( $result ) | |
} | |
} | |
); | |
return $promise; | |
}, | |
@records | |
); | |
}, | |
sub | |
{ | |
warn 'SECOND PROMISE FAILED: ' . join "\n", @_; | |
} | |
)->then | |
( | |
sub | |
{ | |
#my $result = [ map { $_->[0] } @_ ]; | |
warn 'DONE WRAPPING THINGS UP AFTER SECOND PROMISE FULFILLED'; | |
warn 'START: ' . $start; | |
warn 'FINISH: ' . scalar localtime; | |
return; | |
}, | |
sub | |
{ | |
warn 'WRAPUP ACTIONS FAILED: ' . join "\n", @_; | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment