Created
February 4, 2022 08:40
-
-
Save rueian/703a1c6fbf879fee5df36958477f9f85 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| func writing(outgoing *bufio.Writer, requests <-chan request, waiting chan request) (err error) { | |
| var req request | |
| var more = true | |
| for more && err == nil { | |
| select { | |
| case req, more = <-requests: | |
| waiting <- req // <- push req into another waiting channel | |
| _, err = outgoing.Write(req.body) | |
| continue | |
| default: | |
| } | |
| if err = outgoing.Flush(); err == nil { | |
| req, more = <-requests | |
| waiting <- req // <- push req into another waiting channel | |
| _, err = outgoing.Write(req.body) | |
| } | |
| } | |
| return err | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment