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
{{ message }}
Repository navigation
Add non-blocking option to cursors for changefeeds #3529
It would be a lot easier to work with changefeeds if they had some method of doing a (more or less) non-blocking read on them. For example, the following blocks unless something else adds a change:
feed=r.table('smith').changes().run(conn)
next(feed) # blocks forever here without outside intervention
To avoid this we could mimic Python's Queue object and add a .get([block, [timeout]]) method to the Cursor object that would either return an already fetched item, or do a short-timeout request for the next object(s) and if that got nothing raise an exception based on Queue.Empty. There is a similar model to follow for the Ruby driver in the thread module also named Queue that could be used the same way, and this is not an issue in JavaScript.
feed=r.table('smith').changes().run(conn)
whileTrue:
try:
item=feed.get(False)
# work on itemexceptQueue.Empty:
# do something else
For completeness we could also add get_nowait() which is equivalent to get(block=False, timeout=0).
This is slightly orthogonal but related to an number of other issues:
@larkost , @coffeemug , @timmaxw, @mlucy and I concluded in an offline discussion that we should have an optarg cursor.next(wait=False) to make the element retrieval non-blocking.
This would complement the native async support for reading from cursors.
If there's no element, cursor.next(wait=False) will throw an exception.
An open question is if you should be able to pass a timeout instead of False. I don't think it's necessary, but also don't oppose it if it's easy to do.
Activity
gchpaco commentedon Jan 28, 2015
Ruby equivalent is #3678.
danielmewes commentedon Feb 10, 2015
Moving to 2.0.
@larkost , @coffeemug , @timmaxw, @mlucy and I concluded in an offline discussion that we should have an optarg
cursor.next(wait=False)to make the element retrieval non-blocking.This would complement the native async support for reading from cursors.
If there's no element,
cursor.next(wait=False)will throw an exception.An open question is if you should be able to pass a timeout instead of
False. I don't think it's necessary, but also don't oppose it if it's easy to do.coffeemug commentedon Feb 10, 2015
I don't think this would be particularly useful. I'd keep that out and add it people demand it.
mlucy commentedon Feb 10, 2015
I'd add it, personally: I've wanted it before and it isn't that hard.
larkost commentedon Feb 12, 2015
Having a numeric value would be nice, and simplify some parts of testing (otherwise I will just wrap it like I do now).
danielmewes commentedon Feb 12, 2015
Let's do it with a timeout then.
danielmewes commentedon Feb 16, 2015
We should add this in Python and Ruby.
Assigning @Tryneus.
Tryneus commentedon Feb 17, 2015
This has been added to the python driver in
nextin commit 3713807. Review was 2621. Will be in release 2.0. Working on the ruby driver next.Tryneus commentedon Feb 25, 2015
This feature has been implemented for the Ruby driver and is up in review 2650.
Tryneus commentedon Mar 2, 2015
The ruby driver implementation has been merged to
nextin commit 9ebc172. Will be in release 2.0.