closer

package
v1.3.2-0...-808ebe2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package closer provides utility to close readers or writers chain in LIFO order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Closers

type Closers []func() error

Closers type is a list of close callbacks, which are invoked in LIFO order.

Closing Writers Chain

Writer Close method can have the following uses:

  • releasing resources
  • flushing internal buffers
  • write stream tail

For reasons above, it is necessary to call close methods in the correct order, see example bellow:

WRITE        >>> BufferIn -> GzipWriter -> BufferOut -> os.File
OPEN                4     <-     3      <-     2     <-    1            (opening the file is the FIRST step)
CLOSE/FLUSH         1     ->     2      ->     3     ->    4            (closing the file is the LAST step)

Closing Readers Chain

Reader Close method is used only to release resources.

The stream ends with an EndOfFile (io.EOF) error, so there is no risk that we have not read everything.

Therefore, we can close the readers in any order, so we use the same LIFO order.

READ io.EOF  <<< BufferOut <- GzipReader <- BufferIn <- os.File
OPEN                4      <-     3      <-    2     <-    1            (opening the file is the first step)
CLOSE              4/1     <->   3/2     <->  2/3    <->  1/4           (closing the file is the FIRST or the LAST step)

func (*Closers) Append

func (v *Closers) Append(closers ...func() error) *Closers

func (*Closers) Close

func (v *Closers) Close() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL