-
-
Save kayrus/2753b4710e78dd0f5e544baa0f5f4fa1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"os" | |
) | |
func main() { | |
for i := 0; i<3; i++ { | |
go func(dst io.Writer, src io.Reader) error { | |
var err error | |
buf := make([]byte, 32*1024) | |
for { | |
fmt.Print("prepare to read\n") | |
nr, er := src.Read(buf) | |
fmt.Printf("read done: %d bytes\n", nr) | |
if nr > 0 { | |
fmt.Print("prepare to write\n") | |
nw, ew := dst.Write(buf[0:nr]) | |
fmt.Printf("write done: %d bytes\n", nw) | |
if ew != nil { | |
fmt.Print("interrupt ew != nil\n") | |
err = ew | |
break | |
} | |
if nr != nw { | |
fmt.Print("interrupt nr != nw\n") | |
err = io.ErrShortWrite | |
break | |
} | |
} | |
if er == io.EOF { | |
fmt.Print("interrupt EOF\n") | |
break | |
} | |
if er != nil { | |
fmt.Print("interrupt er != nil\n") | |
err = er | |
break | |
} | |
} | |
fmt.Print("Copy finished\n") | |
return err | |
}(os.Stdout, os.Stdin) | |
var ans string | |
fmt.Fprint(os.Stderr, "Scanning:\n") | |
_, err := fmt.Scanf("%s\n", &ans) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "Failed to scan: %#v\n",err.Error()) | |
} else { | |
fmt.Fprintf(os.Stderr, "What was scanned at i=%d: \"%s\"\n",i,ans) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment