Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect/listen and publish/subscribe/unsubscribe with deferred #14

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

oubiwann
Copy link
Collaborator

This is the beginning of some work that I'll be doing to bring the APIs in txZMQ more inline with the APIs in twisted.internet.endpoints (see http://twistedmatrix.com/documents/current/core/howto/endpoints.html); as of Twisted 10, this is the recommended mechanism for connected resources in Twisted.

I've got a blueprint up on Launchpad that lists the related work items:
https://blueprints.launchpad.net/txzmq/+spec/twisted-api-symmetry

All this being said, if any of these changes make folks uncomfortable, feel free to reject them. No pressure :-)

Also, if folks want me to implement backwards compatibility for this change, I can do that (or put it in a separate branch, if you prefer).

Without further ado, here is what has changed in this branch:

  • connection no longer happens with object instantiation
  • instead, one has to call "connect" (for clients) or "listen" (for servers)
  • ZmqConection.connect and .listen return deferreds which can now be used for running callbacks
  • these methods are what now receives the ZmqFactory instance (like Twisted Endpoints)
  • ZmqPubConnection.publish and ZmqSubConnection.subscribe, .unsubscribe now return deferreds
  • socket creation logic now happens in its own (private) method
  • factory set-up now happens in _connectOrBind (since this is where the meat of the connection logic actually happens)

There's a caveat here, though: as indicated in the docstrings, the use of deferreds here is an artifice; they're providing API compatibility with Twisted-proper (the real async work is happening in ZMQ).

Duncan McGreggor added 17 commits January 10, 2012 14:42
 * removed the implicit connect or bind in the constructor
 * added a listen method (to be called by servers)
 * added a connect method (to be called by clients)

There are new private methods as well; these were created to make the code
easier to test and easier to read.

This change also updates the example (and moves it to a new home) as well as
the unit tests.
* Cleaned up example a little more.
…ses.

* Added new pubsub examples that make use of the new deferred-using methods.
* Did a little more cleanup on the old pubsub example.
* Added a base module for pubsub examples (for shared code that was distracting
from the essesnce of the examples).
…ts and

servers.
* Cleaned up pyflakes in the examples.
* Tweaked the phrasing in the README.
* Added docstrings explaining the use of deferreds.
* Added try/except/else blocks around connect and listen code.
* Added success and fail unit tests for connect and listen.
…il if an

exception is raised.
* Added unit tests (passing and failing) for the all the methods that have been
updated (or created) to return deferreds.
* Added more custom txZMQ exceptions.
…ome errors

that cropped up when running the tests in a virtual environment..
* Refactored code out of error checking into a new utils module.
* Added the examples directory to the "check" target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant