-
Notifications
You must be signed in to change notification settings - Fork 118
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
Synchronous calls from an asynchronous context #339
Comments
the code
should actually work. Using |
@bfredl Thanks for the quick follow-up. I'm sorry, you're absolutely right. The code does indeed work. In fact, I'm making that call from a thread. In that case, is my solution using import threading
class MyPlugin:
@neovim.autocmd(..., sync=False)
def my_async_cmd(self):
def func():
code = self._vim.current.buffer[:]
...
thread = threading.Thread(target=func)
thread.start() |
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: