Skip to content

Instantly share code, notes, and snippets.

@tsonglew
Created September 29, 2017 12:43
Show Gist options
  • Save tsonglew/b7c22c2508d234a41dc9bfd0bfc57cec to your computer and use it in GitHub Desktop.
Save tsonglew/b7c22c2508d234a41dc9bfd0bfc57cec to your computer and use it in GitHub Desktop.
A leaky buffer
package main
var freeList = make(chan *Buffer, 100)
var serverChan = make(chan *Buffer)
func client() {
for {
var b *Buffer
select {
case b = <-freeList:
default:
b = new(Buffer)
}
load(b)
serverChan <- b
}
}
func server() {
for {
b := <-serverChan
process(b)
select {
case freeList <- b:
default:
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment