asyncio

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package asyncio provides context-aware alternatives to io methods.

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("asyncio: Context canceled and timeout expired")

ErrCanceled is returned by Read() or Write() when the context was canceled and the timeout expired.

Functions

func Copy

func Copy(ctx context.Context, timeout time.Duration, dst io.Writer, src io.Reader) (written int64, err error)

Copy is like io.Copy, but wrapping dst and src using Writer and Reader methods.

func CopyLeak

func CopyLeak(ctx context.Context, dst io.Writer, src io.Reader) (written int64, err error)

CopyLeak is like Copy with timeout being half the memory leak timeout. It also prints a debug message when the memory leak detector is enabled.

func Read

func Read(ctx context.Context, timeout time.Duration, reader io.Reader, p []byte) (n int, err error)

Read is a replacement for reader.Read() that returns within timeout after context is canncelled.

Read can not cancel the underlying I/O; instead it is left running in a seperate goroutine.

func Reader

func Reader(ctx context.Context, timeout time.Duration, reader io.Reader) io.Reader

Reader returns a new reader with the Read method calling Read().

func StdCopy

func StdCopy(ctx context.Context, timeout time.Duration, dstout, dsterr io.Writer, src io.Reader) (written int64, err error)

StdCopy is like stdcopy.StdCopy, but wrapping readers using Reader() and writers using Writer().

func StdCopyLeak

func StdCopyLeak(ctx context.Context, dstout, dsterr io.Writer, src io.Reader) (written int64, err error)

StdCopyLeak is like StdCopy with timeout being half the memory leak timeout.

func Wait

func Wait(ctx context.Context, timeout time.Duration, action, cancel func()) (ok bool)

Wait performs action in a concurrent goroutine and returns true once it has completed.

When ctx is canceled, and f is not yet finished, calls cancel. Then waits at most timeout and, if f has not returned, returns false. When cancel is nil, it is not called.

func Write

func Write(ctx context.Context, timeout time.Duration, writer io.Writer, p []byte) (n int, err error)

Write is a replacement for writer.Write() that returns within timeout after context is cancelled.

Write can not cancel the underlying I/O; instead it is left running in a seperate goroutine.

func Writer

func Writer(ctx context.Context, timeout time.Duration, writer io.Writer) io.Writer

Writer returns a new writer with the Write method calling Write().

Types

This section is empty.

Jump to

Keyboard shortcuts

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