Cancelreader - A cancelable reader for Go

CancelReader

Latest Release Go Doc Software License Build Status Go ReportCard

A cancelable reader for Go

This package is based on the fantastic work of Erik Geiser in Charm's Bubble Tea framework.

Usage

NewReader returns a reader with a Cancel function. If the input reader is an *os.File, the cancel function can be used to interrupt a blocking Read call. In this case, the cancel function returns true if the call was canceled successfully. If the input reader is not an *os.File, the cancel function does nothing and always returns false.

r, err := cancelreader.NewReader(file)
if err != nil {
    // handle error
    ...
}

// cancel after five seconds
go func() {
    time.Sleep(5 * time.Second)
    r.Cancel()
}()

// keep reading
for {
    var buf [1024]byte
    _, err := r.Read(buf[:])

    if errors.Is(err, cancelreader.ErrCanceled) {
        fmt.Println("canceled!")
        break
    }
    if err != nil {
        // handle other errors
        ...
    }

    // handle data
    ...
}

Implementations

  • The Linux implementation is based on the epoll mechanism
  • The BSD and macOS implementation is based on the kqueue mechanism
  • The generic Unix implementation is based on the posix select syscall

Caution

The Windows implementation is based on WaitForMultipleObject with overlapping reads from CONIN$. At this point it only supports canceling reads from os.Stdin.

Owner
Christian Muehlhaeuser
Geek, Gopher, Software Developer, Maker, Opensource Advocate, Tech Enthusiast, Photographer, Board and Card Gamer
Christian Muehlhaeuser
Similar Resources

csv reader/writer.

IO csv reader sample version 0.0.1-SNAPSHOT Goals: main: read huge file, hex substring, write to new file. cmd/v2 version can read and write use ony o

Nov 4, 2021

csv reader/writer and csv generator.

IO csv reader sample version 0.0.1-SNAPSHOT Goals: main: read huge file, hex substring, write to new file. repo has 2 version. v1 can read a file and

Nov 4, 2021

terminal rss reader

TODO Add author field [x] Add Source as own type to support both http sources and file types sources [x] Move Load http call to own method that Load m

Nov 7, 2021

yarr (yet another rss reader) is a web-based feed aggregator

yarr (yet another rss reader) is a web-based feed aggregator

yarr (yet another rss reader) is a web-based feed aggregator which can be used both as a desktop application and a personal self-hosted server.

Jan 2, 2023

osu! database file format flexible reader

Example usage package main import ( "fmt" "github.com/l3lackShark/reader" types "github.com/l3lackShark/reader/types" ) type agent struct { Osu

Nov 24, 2021

Named csv reader for go

Named csv reader Package named csv reader provides methods to easly read csv files and parse columsn to basic types. This package is not a CSV parser,

Nov 28, 2021

A bit reader tool written in golang

A bit reader tool written in golang

Dec 12, 2021

Go MBtiles reader

MBTiles Reader for Go A simple Go-based mbtiles reader. Supports JPG, PNG, WebP, and vector tile tilesets created according to the mbtiles specificati

May 7, 2022

Wrap byte read options with uniform interface for io.Reader and byte slice

nibbler Nibble chunks from Reader streams and slice in a common way Overview This is a golang module that provides an interface for treating a Reader

Dec 23, 2021

Simple binary reader and writer

Simple binary reader and writer

Simple Binary Stream Reader/Writer This package contains a set of simple utility reader and writer that can be used to efficiently read/write binary i

Oct 30, 2022

TXQR (Animated QR data transfer) demo reader app for iOS

TXQR (Animated QR data transfer) demo reader app for iOS

TXQR Reader for iOS txqr-reader is a demo app in Swift that reads animated QR code and shows file. Currently it expects file to be an JPEG image. Just

Nov 24, 2022

Multi producer and multi-reader lockless ring buffer in go using generics from the go 1.18beta release

LocklessGenericRingBuffer This is an implementation of a multi producer, multi r

Dec 25, 2022

HLF smart-bft WAL files reader

WAL Reader Utility for reading Hyperledger Fabric SmartBFT WAL files. Install go install gitlab.n-t.io/atmz/walreader@latest Read WAL file walreader

Jan 14, 2022

Go-sql-reader - Go utility to read the externalised sql with predefined tags

go-sql-reader go utility to read the externalised sql with predefined tags Usage

Jan 25, 2022

Vtterm - An raw-mode vt100 screen reader

#VT100 TERMINAL This is a vt100 screen reader ( clone of jaguilar/v100 ) and inc

Feb 26, 2022

Perform external sorting on io.Reader

external-sort This repo describes an algorithm to sort data from a stream with a fixed amount of memory necessary that can be specified. The overall i

Dec 25, 2022

A cli HackerNews reader, using HackerNews API.

HackerReader STILL WIP A cli HackerNews reader, using the HackerNews API. I mainly created this as a way to play around with Bubble Tea, Lip Gloss, an

Feb 13, 2022

Hntoebook - Converts the best HN stories to .mobi format to be read using an e-reader

Hntoebook - Converts the best HN stories to .mobi format to be read using an e-reader

HN to E-Book What? This program converts the best HN stories to .mobi format to

Jan 2, 2023

A Hacker News reader focused on content and readability.

HN.HSBLHSN.ME A HackerNews reader written in Go and React. It focuses on content and readability. Demo You can check the final result here at https://

Oct 16, 2022
Comments
  • Fix support for redirected stdin on Windows

    Fix support for redirected stdin on Windows

    Fixes #7.

    I updated the README here, and added a check to NewReader to ensure the supplied reader is a console.

    I also created a unit test that runs NewReader in a child process with a redirected stdin. It should work on both unix and Windows platforms. Without this fix, the test will fail on Windows.

  • Redirected stdin not handled properly on Windows

    Redirected stdin not handled properly on Windows

    On Windows, NewReader(os.Stdin) will replace stdin with a handle to the console, even when stdin was previously redirected from a pipe.

    This can be fixed by returning newFallbackCancelReader(reader) when stdin is not a console.

A simple and light excel file reader to read a standard excel as a table faster | 一个轻量级的Excel数据读取库,用一种更`关系数据库`的方式解析Excel。

Intro | 简介 Expect to create a reader library to read relate-db-like excel easily. Just like read a config. This library can read all xlsx file correct

Dec 19, 2022
Optimized bit-level Reader and Writer for Go.

bitio Package bitio provides an optimized bit-level Reader and Writer for Go. You can use Reader.ReadBits() to read arbitrary number of bits from an i

Dec 1, 2022
Load environment variables from `.env` or `io.Reader` in Go.

gotenv Load environment variables from .env or io.Reader in Go. Usage Put the gotenv package on your import statement: import "github.com/subosito/got

Dec 30, 2022
yet another rss reader
yet another rss reader

yarr yarr (yet another rss reader) is a web-based feed aggregator which can be used both as a desktop application and a personal self-hosted server. I

Dec 29, 2022
Pure Go SQLite file reader

Package SQLittle provides pure Go, read-only, access to SQLite (version 3) database files. What SQLittle reads SQLite3 tables and indexes. It iterates

Oct 12, 2022
Golang io.Reader and io.Writer but with limits

LimitIO io.Reader and io.Writer with limit.

Dec 14, 2022
Glow is a terminal based markdown reader designed from the ground up to bring out the beauty—and power—of the CLI.💅🏻
Glow is a terminal based markdown reader designed from the ground up to bring out the beauty—and power—of the CLI.💅🏻

Glow Render markdown on the CLI, with pizzazz! What is it? Glow is a terminal based markdown reader designed from the ground up to bring out the beaut

Dec 30, 2022
Minimalist and opinionated feed reader
Minimalist and opinionated feed reader

Miniflux 2 Miniflux is a minimalist and opinionated feed reader: Written in Go (Golang) Works only with Postgresql Doesn't use any ORM Doesn't use any

Jan 3, 2023
Use Google Cloud KMS as an io.Reader and rand.Source.

Google Cloud KMS Go io.Reader and rand.Source This package provides a struct that implements Go's io.Reader and math/rand.Source interfaces, using Goo

Dec 1, 2022
go-linereader: A small library for streaming lines from an io.Reader.

go-linereader: A small library for streaming lines from an io.Reader.

Oct 25, 2021