neovim/python-client — pull request #72 by bfredl (2014-12-21 13:38:56+00:00)
Title: [WIP/RFC] allow polling on a provided fd

This allows a plugin to poll for readability and/or writability on a specified fd.
[here](https://gist.github.com/bfredl/5f90c9ebca958401b4ee) is an example integrating with a zeromq socket.

However, I'm not actually sure we want to spawn a greenlet for every poll event, because this event doesn't imply that there actually is useful data that needs to be handled. ( For instance, `zmq` uses the same fd also for internal communication with its worker threads and so at times there could be lots of spurious poll events) Perhaps its better to spawn a greenlet only when there is message, for instance:
```
def _on_poll(self, fd, read, write):
while self.sock.getsockopt(zmq.EVENTS) & zmq.POLLIN:
self.vim.session.schedule(lambda: self.on_msg( self.sock.recv()))
```
One might even want back to yield back to an existing greenlet that is blocking on receiving (or sending) on the fd.
Or it could be that spawning new greenlets is so cheap, that its not worth bothering avoiding it, I don't know.