kalfa/python-rfxcom — pull request #1 by kalfa (2014-06-13 13:08:29+00:00)
Title: Yield in setup and general improvements

Here's the change for having setup() a bit more readable.
Unfortunately I had to split setup() and _setup().

A coroutine is a generator, which means that needs something to yield from it to generate something.

Simply doing:
loop.call_later(setup)

def setup(self):
yield from foo
log(something)
yield from bar

won't work, since when setup() is called back by the loop, will return a generator, which needs something to have it produce the results. The only way for the loop to have it done is to:
- have the generator yielded from by some other coroutine
- use Futures (asyncio.async() in this case)

In other terms, setup now removes itself as writer and then calls asynchronously _setup() which eventually will add the default writer, after having setup everything.

It should not be a problem, flow-wise, i find just uglier than I though, to have to split it.

Also, I updated some of the unittests you amended, for completeness:
- check that the callback is also called, after a read
- that in case of empty queue, no blocking write() is called