cancel

package module
v0.0.0-...-e45b4c0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 7 Imported by: 0

README

cancel

Cancellable readers in golang, modified from bubbletea

Original Author: https://github.com/erikgeiser

Documentation

Overview

nolint:revive

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = fmt.Errorf("read cancelled")

Functions

This section is empty.

Types

type File

type File interface {
	io.ReadWriteCloser

	// Fd returns its file descriptor
	Fd() uintptr

	// Name returns its file name.
	Name() string
}

File represents an input/output resource with a file descriptor.

type Reader

type Reader interface {
	io.ReadCloser

	// Cancel cancels ongoing and future reads an returns true if it succeeded.
	Cancel() bool
}

Reader is a io.Reader whose Read() calls can be cancelled without data being consumed. The Reader has to be closed.

func NewReader

func NewReader(reader io.Reader) (Reader, error)

NewReader returns a reader and a cancel function. If the input reader is an File, the cancel function can be used to interrupt a blocking call read call. In this case, the cancel function returns true if the call was cancelled successfully. If the input reader is not a File, the cancel function does nothing and always returns false. The linux implementation is based on the epoll mechanism.

Jump to

Keyboard shortcuts

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