Documentation for routine close

Documentation for routine close, assembled from the following types:

class Channel

From Channel

(Channel) method close

Defined as:

method close(Channel:D:)

Close the Channel, normally. This makes subsequent send calls die with X::Channel::SendOnClosed. Subsequent calls of .receive may still drain any remaining items that were previously sent, but if the queue is empty, will throw an X::Channel::ReceiveOnClosed exception. A Seq produced by an @() or by the .list method will not terminate until this has been done.

my $c =;
CATCH { default { put .^name''.Str } };
# OUTPUT: «X::Channel::SendOnClosed: Cannot send a message on a closed channel␤» 

Please note that any exception thrown may prevent .close from being called, this may hang the receiving thread. Use a LEAVE phaser to enforce the .close call in this case.

role IO

From IO

(IO) method close

To close an open file handle, simply call its close method:

my $fh = open("path-to-file");
# ... do stuff with the file 

It is also possible to call this as a sub, thus the example above can be written equivalently like so:

my $fh = open("path-to-file");
# ... do stuff with the file 
close $fh;

When a file was opened for writing, closing it is important to ensure that all contents are actually written to the file. You may want to consider using a LEAVE phaser to guard against exceptions in your code that could prevent your program from reaching the line with $fh.close.

class IO::Handle

From IO::Handle

(IO::Handle) method close

Will close a previously opened filehandle.


class IO::Pipe

From IO::Pipe

(IO::Pipe) method close

method close(IO::Pipe: --> Proc:D)

Closes the pipe and returns Proc object from which the pipe originates.

role IO::Socket

From IO::Socket

(IO::Socket) method close

method close(IO::Socket:D)

Closes the socket.

Fails if the socket is not connected.

class IO::Socket::Async

From IO::Socket::Async

(IO::Socket::Async) method close

method close()

Close the connected client IO::Socket::Async which will have been obtained from the listen Supply or the connect Promise.

In order to close the underlying listening socket created by listen you can close the Tap. See listen for examples.

class Tap

From Tap

(Tap) method close

method close(Tap:D:)

Closes the tap.