Standard library / io

io.PipeReader.CloseWithError()

Closes the reader with an error delivered to the writer. A nil argument uses ErrClosedPipe. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (r *PipeReader) CloseWithError(err error) error

Parameters & Attributes

NameTypeDescription
errerrorError communicated to the other end.

Return Value

error

Closes the reader with an error delivered to the writer.

Working Example

Example Snippetgo
package main
import (  "errors"  "fmt"  "io")
func main() {  r, w := io.Pipe()  defer w.Close()  sentinel := errors.New("stop")  r.CloseWithError(sentinel)  _, e := w.Write([]byte("x"))  fmt.Println(e == sentinel)}
Go Reference