Last active
July 9, 2021 20:16
-
-
Save tommybutler/57e8b6bc01c7672144069da13c7e424c to your computer and use it in GitHub Desktop.
Mojo Promise Map Concept
This file contains hidden or 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
# inside my mojo route... | |
my $result = $library->run_object_method_that_runs_mojo_promise_map(); | |
if ( Scalar::Util::blessed( $result ) && $result->isa( 'Mojo::Promise' ) ) | |
{ | |
$c->render_later(); | |
my $start = scalar localtime; | |
return $result->then | |
( | |
sub | |
{ | |
my $json = | |
{ | |
start => $start, | |
finish => scalar localtime, | |
result => [ @_ ] | |
}; | |
$c->respond_to( any => { json => $json, status => 200 } ) | |
}, | |
sub | |
{ | |
my $json = { errors => [ @_ ] }; | |
$c->respond_to( any => { json => $json, status => 500 } ) | |
}, | |
); | |
} | |
else | |
{ | |
$c->respond_to( any => { json => $result, status => 200 } ); | |
return | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment