writemux

package module
v1.0.1 Latest Latest
Warning

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

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

README

writemux

import "github.com/cognusion/go-writemux"

Overview

Index

Package files

writemux.go

Variables

var (
    // ErrorNoWriters is returned by a WriteMux created by NewWriteMuxWithErrors,
    // when there are zero writers in the mux.
    ErrorNoWriters = errors.New("there are no writer in the mux")
)

type WriteMux

type WriteMux struct {
    // contains filtered or unexported fields
}

WriteMux is a WriteCloser that can have WriteClosers added and removed from the group, so that Write() and Close() calls can be mirrored to all mux members. All operations after proper initialization are goro-safe.

func NewWriteMux
func NewWriteMux() WriteMux

NewWriteMux returns an initialized WriteMux. Writes that generate errors are ignored.

func NewWriteMuxWithErrors
func NewWriteMuxWithErrors() WriteMux

NewWriteMuxWithErrors returns an initialized WriteMux. Writes that generate errors cause the Write to fail, returning a wrapped error with the index of the member causing the error. Subsequent members are not written to.

func (*WriteMux) Add
func (w *WriteMux) Add(wc io.WriteCloser) (index string)

Add will add the WriteCloser to the mux, returning an index that can be used in the future to remove the WriteCloser from the mux. The index should not be intuited as any usable value beyond the future parameter to Remove().

func (*WriteMux) Close
func (w *WriteMux) Close() error

Close sequentially closes all members of the mux.

func (*WriteMux) Remove
func (w *WriteMux) Remove(index string)

Remove takes the specified index, and removes it from the mux.

func (*WriteMux) Write
func (w *WriteMux) Write(p []byte) (n int, err error)

Write sequentially writes len(p) bytes to each WriteCloser in the mux. Depending which New... method was used to create the mux, the writes are blind or are passed back, halting the range.


Generated by godoc2md

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorNoWriters is returned by a WriteMux created by NewWriteMuxWithErrors,
	// when there are zero writers in the mux.
	ErrorNoWriters = errors.New("there are no writer in the mux")
)

Functions

This section is empty.

Types

type WriteMux

type WriteMux struct {
	// contains filtered or unexported fields
}

WriteMux is a WriteCloser that can have WriteClosers added and removed from the group, so that Write() and Close() calls can be mirrored to all mux members. All operations after proper initialization are goro-safe.

func NewWriteMux

func NewWriteMux() WriteMux

NewWriteMux returns an initialized WriteMux. Writes that generate errors are ignored.

func NewWriteMuxWithErrors

func NewWriteMuxWithErrors() WriteMux

NewWriteMuxWithErrors returns an initialized WriteMux. Writes that generate errors cause the Write to fail, returning a wrapped error with the index of the member causing the error. Subsequent members are not written to.

func (*WriteMux) Add

func (w *WriteMux) Add(wc io.WriteCloser) (index string)

Add will add the WriteCloser to the mux, returning an index that can be used in the future to remove the WriteCloser from the mux. The index should not be intuited as any usable value beyond the future parameter to Remove().

func (*WriteMux) Close

func (w *WriteMux) Close() error

Close sequentially closes all members of the mux.

func (*WriteMux) Remove

func (w *WriteMux) Remove(index string)

Remove takes the specified index, and removes it from the mux.

func (*WriteMux) Write

func (w *WriteMux) Write(p []byte) (n int, err error)

Write sequentially writes len(p) bytes to each WriteCloser in the mux. Depending which New... method was used to create the mux, the writes are blind or are passed back, halting the range.

Jump to

Keyboard shortcuts

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