coreos/go-etcd — pull request #95 by onsi (2014-02-04 17:26:43+00:00)
Title: Add cancelable AsyncWatch

This involved creating an asyncSendRequest on the go-etcd Client object
asyncSendRequest returns a stop channel that, when closed, attempts to cancel
the connection.

This only works if the connection is in-flight. Which means there is an
intrinsic race that cannot be avoided. If stop is called before the innards of
c.httpClient.Do(req) have reached the point where the request is registered
(and therefore cancelable) then the request will not be cancelled. For short
requests this is OK, the request is returned, and we clean up. For long-running
requests (e.g. watch) the goroutines spawned by net/http and one go-routine per
async call will leak (until the response comes in).

Also: we didn't try changing the behavior of Watch -- we think its interface doesn't quite make sense. AsyncWatch returns three channels: a response channel, an error channel, and a stop channel, and it leaves looping to obtain subsequent watches by following the index to the caller.

If you'd like to add the latter, we think that AsyncWatch should handle the EventIndexCleared error and do its best to jump to the next available index. That might make more sense as a separate pull request, though.