summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Controller/Stationboard.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-09-20 10:52:21 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-09-20 10:52:21 +0200
commit878df847bac8cffb5452af30c3270fbdd6050651 (patch)
treea8a35d8621a83f676179555dac6aa257b6673d7c /lib/DBInfoscreen/Controller/Stationboard.pm
parent93256284a230bda3c8f04e4a9d3ae689a5fe7ff1 (diff)
defer route detail rendering until all requests have completed
Diffstat (limited to 'lib/DBInfoscreen/Controller/Stationboard.pm')
-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,