Standard library / io

io.PipeWriter.Close()

Closes the write end so the reader receives EOF after all delivered bytes. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (w *PipeWriter) Close() error

Return Value

error

Closes the write end so the reader receives EOF after all delivered bytes.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io")
func main() {  r, w := io.Pipe()  defer r.Close()  w.Close()  _, e := r.Read(make([]byte, 1))  fmt.Println(e == io.EOF)}
Go Reference