You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case which I'd think is really common. From an asynchronous context I want to get the result of a synchronous call. E.g., in this asynchronous method I want to access the current buffer content:
classMyPlugin:
@neovim.autocmd(..., sync=False)defmy_async_cmd(self):
# This obviously doesn't work because the function is asynccode=self._vim.current.buffer[:]
Of course, I could hack together my own synchronization construct using e.g. threading.Event:
With that I could now just use code = self._wait_for(lambda: self._vim.current.buffer[:]) to get the code, but this seems really sketchy and I feel there must be an elegant pattern (which would maybe be more obvious to me if I had a firmer grasp of greenlets).
Could you point me in the right direction here? (I've also read #229 but it doesn't seem to refer to the same problem.)
The text was updated successfully, but these errors were encountered:
class MyPlugin:
@neovim.autocmd(..., sync=False)
def my_async_cmd(self):
# This obviously doesn't work because the function is async
code = self._vim.current.buffer[:]
should actually work. Using threading.Event should only be necessary for multi-threaded code. An alternative can also be to use expr='some code' as documented in http://pynvim.readthedocs.io/en/latest/usage/remote-plugins.html, to avoid extra RPC overhead, or to be sure to evaluate the expression in context of the autocmd.
I have a use case which I'd think is really common. From an asynchronous context I want to get the result of a synchronous call. E.g., in this asynchronous method I want to access the current buffer content:
Of course, I could hack together my own synchronization construct using e.g.
threading.Event
:With that I could now just use
code = self._wait_for(lambda: self._vim.current.buffer[:])
to get the code, but this seems really sketchy and I feel there must be an elegant pattern (which would maybe be more obvious to me if I had a firmer grasp of greenlets).Could you point me in the right direction here? (I've also read #229 but it doesn't seem to refer to the same problem.)
The text was updated successfully, but these errors were encountered: