From 4411548d79bd507d3b97c929dfec94fc38fd4bf8 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 16 Sep 2020 20:05:13 +0200 Subject: perform traininfo requests concurrently --- lib/DBInfoscreen/Helper/HAFAS.pm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'lib/DBInfoscreen') diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm index 0206bed..3b55051 100644 --- a/lib/DBInfoscreen/Helper/HAFAS.pm +++ b/lib/DBInfoscreen/Helper/HAFAS.pm @@ -255,28 +255,32 @@ sub get_route_timestamps_p { } my $base = 'https://reiseauskunft.bahn.de/bin/traininfo.exe/dn'; - my ( $trainsearch_result, $trainlink, $traininfo ); + my ( $trainsearch_result, $trainlink ); $self->trainsearch_p(%opt)->then( sub { ($trainsearch_result) = @_; $trainlink = $trainsearch_result->{trainLink}; - return $self->get_json_p( $self->{realtime_cache}, - "${base}/${trainlink}?rt=1&date=$opt{date_yy}&L=vs_json" ); + return Mojo::Promise->all( + $self->get_json_p( + $self->{realtime_cache}, + "${base}/${trainlink}?rt=1&date=$opt{date_yy}&L=vs_json" + ), + $self->get_xml_p( + $self->{realtime_cache}, + "${base}/${trainlink}?rt=1&date=$opt{date_yy}&L=vs_java3" + ) + ); } )->then( sub { - ($traininfo) = @_; + my ( $traininfo, $traindelay ) = @_; + $traininfo = $traininfo->[0]; + $traindelay = $traindelay->[0]; if ( not $traininfo or $traininfo->{error} ) { $promise->reject; return; } - return $self->get_xml_p( $self->{realtime_cache}, - "${base}/${trainlink}?rt=1&date=$opt{date_yy}&L=vs_java3" ); - } - )->then( - sub { - my ($traindelay) = @_; my $ret = {}; my $strp = DateTime::Format::Strptime->new( -- cgit v1.2.3