From 878df847bac8cffb5452af30c3270fbdd6050651 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 20 Sep 2020 10:52:21 +0200 Subject: defer route detail rendering until all requests have completed --- lib/DBInfoscreen/Controller/Stationboard.pm | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'lib') 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( @@ -603,6 +613,14 @@ sub render_train { # nop } )->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', -- cgit v1.2.3