aが等しくinfo
なるまでバックグラウンドで実行されるように、これを書き直すにはどうすればよいですか?$aw
result
#!/usr/bin/env perl
use 5.12.0;
use warnings;
use Term::ReadLine;
my $term = Term::ReadLine->new( 'something' );
$term->ornaments( 0 );
sub info {
# in the real script this runs some computations instead of the sleep
# and returns some information.
my ( $time ) = @_;
sleep $time;
return $time * 2;
}
my $value_returned_by_info = info( 10 ); # run this in the background
my $aw;
$aw = $term->readline( 'User input: ' );
if ( $aw eq 'result' ) {
# if info() is still running in the background:
# wait until info() returns because "$value_returned_by_info" is needed.
say $value_returned_by_info;
}
else {
# if info() is still running in the background:
# let info() in the background because "$value_returned_by_info" is not needed here.
say $aw;
}
$aw = $term->readline( 'User input: ' );
if ( $aw eq 'result' ) {
# if info() is still running in the background:
# wait until info() returns because "$value_returned_by_info" is needed.
say $value_returned_by_info;
}
else {
# if info() is still running in the background:
# let info() in the background because "$value_returned_by_info" is not needed here.
say $aw;
}
$aw = $term->readline( 'User input: ' );
if ( $aw eq 'result' ) {
# if info() is still running in the background:
# wait until info() returns because "$value_returned_by_info" is needed.
say $value_returned_by_info;
}
else {
# if info() is still running in the background:
# let info() in the background because "$value_returned_by_info" is not needed here.
say $aw;
}
say "End";