Skip Menu |
 

This queue is for tickets about the IO-Async CPAN distribution.

Report information
The Basics
Id: 127818
Status: patched
Priority: 0/
Queue: IO-Async

People
Owner: Nobody in particular
Requestors: DBOOK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: IO::Async::Notifier adopted futures accessor
Download (untitled) / with headers
text/plain 248b
It would be useful to have an accessor to return all Futures currently adopted by the Notifier. e.g. use a Notifier to store Futures that are not yet ready while removing themselves when ready, and then do Future->wait_all($notif->adopted_futures).
Added by attached patch. -- Paul Evans
Subject: rt127818.patch
Download rt127818.patch
text/x-diff 1.3k
=== modified file 'lib/IO/Async/Notifier.pm' --- lib/IO/Async/Notifier.pm 2018-04-02 18:43:40 +0000 +++ lib/IO/Async/Notifier.pm 2019-06-12 15:41:02 +0000 @@ -359,6 +359,24 @@ return $f; } +=head2 adopted_futures + + @f = $notifier->adopted_futures + +I<Since version 0.73.> + +Returns a list of all the adopted and still-pending futures, in no particular +order. + +=cut + +sub adopted_futures +{ + my $self = shift; + + return values %{ $self->{IO_Async_Notifier__futures} }; +} + =head1 CHILD NOTIFIERS During the execution of a program, it may be the case that certain IO handles === modified file 't/07notifier-future.t' --- t/07notifier-future.t 2014-07-11 13:48:36 +0000 +++ t/07notifier-future.t 2019-06-12 15:41:02 +0000 @@ -21,14 +21,22 @@ { my $f = Future->new; + is_deeply( [ $notifier->adopted_futures ], [], + '->adopted_futures initially' ); + $notifier->adopt_future( $f ); is_refcount( $f, 2, '$f has refcount 2 after ->adopt_future' ); is_oneref( $notifier, '$notifier still has refcount 1 after ->adopt_future' ); + is_deeply( [ $notifier->adopted_futures ], [ $f ], + '->adopted_futures after adoption' ); $f->done( "result" ); is_refcount( $f, 1, '$f has refcount 1 after $f->done' ); + + is_deeply( [ $notifier->adopted_futures ], [], + '->adopted_futures finally' ); } # fail


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.