Enforce unique-per-process watcher identifiers #133
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed briefly in #126, this PR proposes enforcing that watcher identifiers are unique-per-process, instead of just unique-per-driver instance. I believe that this will eliminate the potential for some scary and confusing bugs where multiple driver instances are used within a single process and watcher identifiers are unknowingly, possibly silently, passed to the wrong drivers.
I took an approach which allows loop implementations to define their own "local" watcher identifiers, which must be prepared using the provided method getGlobalWatcherId() before being returned to clients. If it isn't really necessary for loop implementations to define their own watcher identifiers then we could potentially simplify further by generating the watcher identifiers incrementally in the abstract
Driver
class. This would have the added benefit of allowing us to distinguish between already removed watcher identifiers and invalid (never returned by the driver) identifiers.If some of you loop implementors could give feedback that would be appreciated; obviously you're more qualified than I am to know whether there are problems with this approach.
@bwoebi
Edit: I'll add tests if people like the feature.