Skip to content

Add non-blocking option to cursors for changefeeds #3529

Closed

Description

@larkost

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)
while True:
    try:
        item = feed.get(False)
        # work on item
    except Queue.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:

Activity

  1. added this to the subsequent milestone on Jan 8, 2015
  2. gchpaco commented on Jan 28, 2015

    @gchpaco
    Contributor

    Ruby equivalent is #3678.

  3. modified the milestones: 2.0, subsequent on Feb 10, 2015
  4. danielmewes commented on Feb 10, 2015

    @danielmewes
    Member

    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.

  5. coffeemug commented on Feb 10, 2015

    @coffeemug
    Contributor

    An open question is if you should be able to pass a timeout instead of False.

    I don't think this would be particularly useful. I'd keep that out and add it people demand it.

  6. mlucy commented on Feb 10, 2015

    @mlucy
    Member

    I'd add it, personally: I've wanted it before and it isn't that hard.

  7. larkost commented on Feb 12, 2015

    @larkost
    CollaboratorAuthor

    Having a numeric value would be nice, and simplify some parts of testing (otherwise I will just wrap it like I do now).

  8. danielmewes commented on Feb 12, 2015

    @danielmewes
    Member

    Let's do it with a timeout then.

  9. danielmewes commented on Feb 16, 2015

    @danielmewes
    Member

    We should add this in Python and Ruby.

    Assigning @Tryneus.

  10. Tryneus commented on Feb 17, 2015

    @Tryneus
    Member

    This has been added to the python driver in next in commit 3713807. Review was 2621. Will be in release 2.0. Working on the ruby driver next.

  11. Tryneus commented on Feb 25, 2015

    @Tryneus
    Member

    This feature has been implemented for the Ruby driver and is up in review 2650.

  12. Tryneus commented on Mar 2, 2015

    @Tryneus
    Member

    The ruby driver implementation has been merged to next in commit 9ebc172. Will be in release 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions