Io module

close

procedure · 7 overloadsSource

No more values will be sent. Fibers waiting to send get .CLOSED; receivers get what is buffered, then .CLOSED.

close :: (channel: *Channel($T))

No more values will be sent. Fibers waiting to send get .CLOSED; receivers get what is buffered, then .CLOSED.

Parameters

channel: *Channel($T)
close :: (stream: Tcp_Stream, now := false) -> Io_Error

Closes the socket. Fibers still waiting on it return .CLOSED. Works for a canceled fiber too, so defer close(conn) always cleans up. With now it closes at once without waiting, for code that cannot block: a Local_Drop, or a fiber that must not give up its turn. Fibers still waiting on the socket are not woken, so use the plain call unless the scheduler is ending.

Parameters

stream: Tcp_Stream
now := false

Returns

close :: (listener: Tcp_Listener, now := false) -> Io_Error

Closes the listening socket. A fiber waiting in accept on it returns .CLOSED. The listener must not be used afterwards. With now it closes at once without waiting and without waking such fibers; use it only where the code cannot block.

Parameters

listener: Tcp_Listener
now := false

Returns

close :: (stream: *Pipe_Stream, now := false) -> Io_Error

Closes this end: the other end reads what was already sent and then 0, writes to it fail, and a fiber waiting in read on this end returns .CLOSED. Close each end once: the memory of both goes when the second one is closed.

Parameters

stream: *Pipe_Stream
now := false

Returns

close :: (file: *Io_File, now := false) -> Io_Error

Closes the file. With now, without going through the engine (see close for a reader).

Parameters

file: *Io_File
now := false

Returns

close :: (reader: Reader, now := false) -> Io_Error

Closes the source behind a reader. With now, nothing waits: use it where the code cannot block (a Local_Drop); fibers still waiting on the source are not woken, so prefer the plain call unless the scheduler is ending.

Parameters

reader: Reader
now := false

Returns

close :: (writer: Writer, now := false) -> Io_Error

Closes the sink behind a writer. A TCP stream or pipe end has a reader and a writer over one connection, so close only one of them.

Parameters

writer: Writer
now := false

Returns

See also