On Mon Aug 27 22:02:20 2012, TEAM wrote:
Show quoted text> Seems that there's a path in IO::Async::Function->call which doesn't
> return the CPS::Future, which can cause problems in e.g. the resolver
> used in IO::Async::Connector->connect, since we end up passing undef as
> one of the parameters to ->needs_all()... seems that we're putting the
> $task in the queue and will get around to it eventually, so maybe this
> could just return $task; ?
Oops. Yes, that'll do it.
Patch attached.
--
Paul Evans
=== modified file 'lib/IO/Async/Function.pm'
--- lib/IO/Async/Function.pm 2012-07-08 22:37:15 +0000
+++ lib/IO/Async/Function.pm 2012-08-28 09:29:00 +0000
@@ -397,7 +397,7 @@
if( !$worker ) {
my $request = freeze( $args );
push @{ $self->{pending_queue} }, [ $request, $task ];
- return;
+ return $task;
}
$self->_call_worker( $worker, args => $args, $task );
=== modified file 't/42function.t'
--- t/42function.t 2012-06-26 18:46:24 +0000
+++ t/42function.t 2012-08-28 09:29:00 +0000
@@ -4,7 +4,7 @@
use IO::Async::Test;
-use Test::More tests => 42;
+use Test::More tests => 44;
use Test::Fatal;
use Test::Refcount;
@@ -104,12 +104,12 @@
my @result;
- $function->call(
+ my $f1 = $function->call(
args => [ 1, 2 ],
on_return => sub { push @result, shift },
on_error => sub { die "Test failed early - @_" },
);
- $function->call(
+ my $f2 = $function->call(
args => [ 3, 4 ],
on_return => sub { push @result, shift },
on_error => sub { die "Test failed early - @_" },
@@ -117,6 +117,9 @@
is( $function->workers, 1, '$function->workers is still 1 after 2 calls' );
+ isa_ok( $f1, "CPS::Future", '$f1' );
+ isa_ok( $f2, "CPS::Future", '$f2' );
+
wait_for { @result == 2 };
is_deeply( \@result, [ 3, 7 ], '@result after both calls return' );