smira/txZMQ — pull request #14 by oubiwann (2012-01-12 22:56:24+00:00)
Title: connect/listen and publish/subscribe/unsubscribe with deferred

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).