summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/DBInfoscreen/Controller/Stationboard.pm26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm
index 220e630..9706b39 100644
--- a/lib/DBInfoscreen/Controller/Stationboard.pm
+++ b/lib/DBInfoscreen/Controller/Stationboard.pm
@@ -442,8 +442,10 @@ sub render_train {
$self->render_later;
- # if wagonorder->is_available_p takes longer than get_route_timestamps_p,
- # we'll have a useless (non-working) wagonorder link. That's okay.
+ my $wagonorder_req = Mojo::Promise->new;
+ my $stationinfo_req = Mojo::Promise->new;
+ my $route_req = Mojo::Promise->new;
+
if ( $departure->{wr_link} ) {
$self->wagonorder->is_available_p( $result, $departure->{wr_link} )
->then(
@@ -455,11 +457,14 @@ sub render_train {
$departure->{wr_link} = undef;
return;
}
+ )->finally(
+ sub {
+ $wagonorder_req->resolve;
+ return;
+ }
)->wait;
}
- # Same for stationinfo (direction of travel). If it's too late and
- # therefore missing, that's okay.
$self->wagonorder->get_stationinfo_p( $result->station_uic )->then(
sub {
my ($station_info) = @_;
@@ -505,6 +510,11 @@ sub render_train {
# errors don't matter here
return;
}
+ )->finally(
+ sub {
+ $stationinfo_req->resolve;
+ return;
+ }
)->wait;
$self->hafas->get_route_timestamps_p( train => $result )->then(
@@ -604,6 +614,14 @@ sub render_train {
}
)->finally(
sub {
+ $route_req->resolve;
+ return;
+ }
+ )->wait;
+
+ # Defer rendering until all requests have completed
+ Mojo::Promise->all( $wagonorder_req, $stationinfo_req, $route_req )->then(
+ sub {
$self->render(
'_train_details',
departure => $departure,