Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Conversation

@jhump
Copy link
Contributor

@jhump jhump commented Dec 8, 2016

I'd like to be able to setup multiple watches and more carefully control how watch logic is dispatched. With the existing APIs, which always create single-shot channels, I had two choices:

  1. Spin off a goroutine per watch that would consume the event and then push it into another (shared) channel. A single goroutine consuming the shared channel (with interleaved events) can then decide how to dispatch.
  2. Use reflection (reflect.Select(...)) so that a single goroutine can try to consume events from all of the watch channels. This goroutine can then decide how to dispatch. There is non-trivial overhead in both performance and in terms of cognitive overhead as the resulting code is more complex. The overhead arises from both the use of reflection and the need to manage the set of watches in a correct way.

Neither of these is ideal to me. Also, neither allow me to receive events in an order that is guaranteed to be the same as the order they were delivered from Zookeeper (which has nice properties in terms of reasoning about the order of events received, including potentially redundant events, when doing something like watching an entire sub-tree).

This pull request provides new API with very small surface area: GetWChannel, ChildrenWChannel, and ExistsWChannel that allow the caller to provide the channel that will be used to send the watch event.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.2%) to 82.39% when pulling c726434 on jhump:jh/allow-reuse-channel-for-watches into 1d7be4e on samuel:master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants