Standard library / io
io.PipeReader.Close()
Closes the read end so pending or future writes fail with ErrClosedPipe unless a custom error was supplied. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (r *PipeReader) Close() errorReturn Value
error
Closes the read end so pending or future writes fail with ErrClosedPipe unless a custom error was supplied.
Working Example
Example Snippetgo
package main
import ( "fmt" "io")
func main() { r, w := io.Pipe() defer w.Close() r.Close() _, e := w.Write([]byte("x")) fmt.Println(e == io.ErrClosedPipe)}