Hello World in Go -- A Memcached Server
dustin.github.com
dustin.github.com
I am a pretty huge fan of git, though (obviously) so all of my new projects and many of my older ones show up on github.
Otherwise, perhaps I'd be posting this source to http://patch-tag.com/ instead. :)
This stuff isn't entirely clear to me, so maybe someone from Go land can clarify.
From the language FAQ (http://golang.org/doc/go_lang_faq.html): "The idea, which has been around for a while, is to multiplex independently executing functions - coroutines, really - onto a set of threads."
That's at least for bigger picture errors. On the method level you should use multiple return values to indicate erros (usually as last return value).
So r, err = write(y) { if (err!=nil) { request.errors <- err; return } }
If I communicate this to the channel and the channel is read by the current goroutine, then the channel's buffer must be large enough to handle the total number of errors that may occur in a single invocation or the goroutine will deadlock on itself.
Basically, it's about allowing me to express my sequence of writes without wrapping each one in an if block.
I could have also done something like
return write(x) && write(y) [...]
or return write(x, y, ...)
but all I really want is to stop writing when a write fails and have the goroutine exit.I've seen a couple people suggest using a channel for this. Containing the write within an object of sorts to contain that boolean would do roughly the same thing. I'd still need to somehow unwind the stack quickly to even know that that channel has something waiting on it.