iopipe

package module
v0.0.0-...-929a6e3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: MIT Imports: 3 Imported by: 0

README

Parallel IO Pipe

iopipe provides the function Parallel to create a synchronous in memory pipe and lets you write to and read from the pipe parallely.

Usage

// Writes `Hello world` to standard output
err := iopipe.Parallel(context.Background(), func(ctx context.Context, w io.Writer) error {
    _, err := fmt.Fprint(w, "Hello World")
    return err
}, func(ctx context.Context, r io.Reader) error {
    _, err := io.Copy(os.Stdout, pr)
    return err
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parallel

func Parallel(ctx context.Context, write Writer, read Reader) error

Parallel creates a synchronous in memory pipe, runs reader and writer functions as go routines and waits until both of them are quits. It closes the reader and writer at the end of functions. ctx is cancelled automatically if any of the functions returns an error

It uses io.Pipe under the hood, see https://pkg.go.dev/io#Pipe for details.

Types

type Reader

type Reader func(context.Context, io.Reader) error

type Writer

type Writer func(context.Context, io.Writer) error

Jump to

Keyboard shortcuts

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