Acme-Sort-Sleep
view release on metacpan or search on metacpan
local/lib/perl5/IO/Async/Handle.pm view on Meta::CPAN
exists $params{read_handle} ? ( read_handle => $params{read_handle} ) : (),
exists $params{write_handle} ? ( write_handle => $params{write_handle} ) : (),
);
}
=head2 set_handle
$handle->set_handle( $fh )
Shortcut for
$handle->configure( handle => $fh )
=cut
sub set_handle
{
my $self = shift;
my ( $fh ) = @_;
$self->configure( handle => $fh );
}
=head2 close
$handle->close
This method calls C<close> on the underlying IO handles. This method will then
remove the handle from its containing loop.
=cut
sub close
{
my $self = shift;
# Prevent infinite loops if there's two crosslinked handles
return if $self->{handle_closing};
$self->{handle_closing} = 1;
$self->want_readready( 0 );
$self->want_writeready( 0 );
my $read_handle = delete $self->{read_handle};
$read_handle->close if defined $read_handle;
my $write_handle = delete $self->{write_handle};
$write_handle->close if defined $write_handle;
$self->_closed;
}
sub _closed
{
my $self = shift;
$self->maybe_invoke_event( on_closed => );
if( $self->{close_futures} ) {
$_->done for @{ $self->{close_futures} };
}
$self->remove_from_parent;
}
=head2 close_read
=head2 close_write
$handle->close_read
$handle->close_write
Closes the underlying read or write handle, and deconfigures it from the
object. Neither of these methods will invoke the C<on_closed> event, nor
remove the object from the Loop if there is still one open handle in the
object. Only when both handles are closed, will C<on_closed> be fired, and the
object removed.
=cut
sub close_read
{
my $self = shift;
$self->want_readready( 0 );
my $read_handle = delete $self->{read_handle};
$read_handle->close if defined $read_handle;
$self->_closed if !$self->{write_handle};
}
sub close_write
{
my $self = shift;
$self->want_writeready( 0 );
my $write_handle = delete $self->{write_handle};
$write_handle->close if defined $write_handle;
$self->_closed if !$self->{read_handle};
}
=head2 new_close_future
$handle->new_close_future->get
Returns a new L<IO::Async::Future> object which will become done when the
handle is closed. Cancelling the C<$future> will remove this notification
ability but will not otherwise affect the C<$handle>.
=cut
sub new_close_future
{
my $self = shift;
push @{ $self->{close_futures} }, my $future = $self->loop->new_future;
$future->on_cancel(
$self->_capture_weakself( sub {
my $self = shift or return;
( run in 0.594 second using v1.01-cache-2.11-cpan-39bf76dae61 )