Standard library / io
io.PipeWriter.CloseWithError()
Closes the writer and passes the supplied error to the reader; nil becomes EOF. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (w *PipeWriter) CloseWithError(err error) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| err | error | Error communicated to the other end. |
Return Value
error
Closes the writer and passes the supplied error to the reader; nil becomes EOF.
Working Example
Example Snippetgo
package main
import ( "errors" "fmt" "io")
func main() { r, w := io.Pipe() defer r.Close() sentinel := errors.New("stop") w.CloseWithError(sentinel) _, e := r.Read(make([]byte, 1)) fmt.Println(e == sentinel)}