Skip to content

Instantly share code, notes, and snippets.

@rueian
Created February 4, 2022 08:40
Show Gist options
  • Save rueian/703a1c6fbf879fee5df36958477f9f85 to your computer and use it in GitHub Desktop.
Save rueian/703a1c6fbf879fee5df36958477f9f85 to your computer and use it in GitHub Desktop.
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