-
Notifications
You must be signed in to change notification settings - Fork 119
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
[WIP/RFC] allow polling on a provided fd #72
base: master
Are you sure you want to change the base?
Conversation
I've been thinking that it would be best to add automatic greenlet creation as a session filter that is disabled by default and enabled with something like: |
A constraint to consider might be making it convenient for plugins to use greenlets to handle messaging to other sources. Right now in my ipython plugin I do this to wait for a reply asynchrously:
and then in an event callback:
Which "just happens" to work given how the python client library uses greenlets. Perhaps it would be a cleaner abstraction if there was a |
greenlet wrapping can be implemented as decorators, for example: @neovim.plugin
class Plugin(object):
def __init__(self, nvim):
self.nvim = nvim
self.greenlet_nvim = nvim.with_hook(GreenletWrap)
@neovim.greenlet
def handler1(self):
# runs in a greenlet
print(self.greenlet_nvim.eval('1'))
def handler2(self):
# doesnt run in a greenlet
def cb(value):
print value
self.nvim.eval('1', cb) I dont think the greenlet hook is even required, session.request can simply detect if it is being called inside a greenlet and act accordingly(eg: receive a callback as last argument if not inside a greenlet) |
Yeah, I think it would be cleaner API if one doesn't have to use two different
|
Updated, now it has simpler |
Updated. Goes back to spawn a greenlet per default, to behave like a an ordinary (async) neovim command handler or |
This allows a plugin to poll for readability and/or writability on a specified fd.
here 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: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.