Skip to content

Commit

Permalink
Add next to Ruby; add wait to Python next; closes #664
Browse files Browse the repository at this point in the history
  • Loading branch information
Watts Martin committed Mar 4, 2015
1 parent 287fd2a commit a393c80
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 14 deletions.
9 changes: 2 additions & 7 deletions api/javascript/cursors/next.md
Expand Up @@ -3,7 +3,6 @@ layout: api-command
language: JavaScript
permalink: api/javascript/next/
command: next
rb: false
io:
- - cursor
- undefined
Expand All @@ -28,7 +27,7 @@ Get the next element in the cursor.

Calling `next` the first time on a cursor provides the first element of the cursor.

__Example:__ Let's grab the next element!
__Example:__ Retrieve the next element.

```js
cursor.next(function(err, row) {
Expand All @@ -37,11 +36,7 @@ cursor.next(function(err, row) {
});
```

__Note:__ The canonical way to retrieve all the results is to use [each](../each/)
or [toArray](../to_array/). The `next` command should be used only when you may not
retrieve all the elements of a cursor or want to delay some operations.


__Note:__ The canonical way to retrieve all the results is to use [each](../each/) or [toArray](../to_array/). The `next` command should be used only when you may not retrieve all the elements of a cursor or want to delay some operations.

__Example:__ You can retrieve all the elements of a cursor with the `next`
command using recursion.
Expand Down
2 changes: 1 addition & 1 deletion api/javascript/index.md
Expand Up @@ -163,7 +163,7 @@ array.next() → promise

Get the next element in the cursor.

__Example:__ Let's grab the next element!
__Example:__ Retrieve the next element.

```js
cursor.next(function(err, row) {
Expand Down
23 changes: 19 additions & 4 deletions api/python/cursors/next.md
Expand Up @@ -3,7 +3,6 @@ layout: api-command
language: Python
permalink: api/python/next/
command: next
rb: false
related_commands:
for (cursor): each/
list: to_array/
Expand All @@ -13,21 +12,37 @@ related_commands:
# Command syntax #

{% apibody %}
cursor.next()
cursor.next([wait=True])
{% endapibody %}

# Description #

Get the next element in the cursor.

Calling `next` the first time on a cursor provides the first element of the cursor.
The optional `wait` argument specifies whether to wait for the next available element and how long to wait:

__Example:__ Let's grab the next element!
* `True`: Wait indefinitely (the default).
* `False`: Do not wait at all. If data is immediately available, it will be returned; if it is not available, a `RqlDriverError` will be raised.
* number: Wait up the specified number of seconds for data to be available before raising `RqlDriverError`.

The behavior of `next` will be identical with `False`, `None` or the number `0`.

Calling `next` the first time on a cursor provides the first element of the cursor. If the data set is exhausted (e.g., you have retrieved all the documents in a table), a `StopIteration` error will be raised when `next` is called.

__Example:__ Retrieve the next element.

```py
cursor = r.table('superheroes').run(conn)
doc = cursor.next()
```

__Example:__ Retrieve the next element on a [changefeed](/docs/changefeeds/python), waiting up to five seconds.

```py
cursor = r.table('superheroes').changes().run(conn)
doc = cursor.next(wait=5)
```

__Note:__ RethinkDB sequences can be iterated through via the Python [Iterable][it] interface. The canonical way to retrieve all the results is to use a [for...in](../each/) loop or [list()](../to_array/).

[it]: https://docs.python.org/3.4/library/stdtypes.html#iterator-types
5 changes: 3 additions & 2 deletions api/python/index.md
Expand Up @@ -163,14 +163,15 @@ conn.noreply_wait()
## [next](next/) ##

{% apibody %}
cursor.next()
cursor.next([wait=True])
{% endapibody %}

Get the next element in the cursor.

__Example:__ Let's grab the next element!
__Example:__ Retrieve the next element.

```py
cursor = r.table('superheroes').run(conn)
doc = cursor.next()
```

Expand Down
48 changes: 48 additions & 0 deletions api/ruby/cursors/next.md
@@ -0,0 +1,48 @@
---
layout: api-command
language: Ruby
permalink: api/ruby/next/
command: next
related_commands:
for (cursor): each/
to_a: to_array/
close (cursor): close-cursor/
---

# Command syntax #

{% apibody %}
cursor.next([true])
{% endapibody %}

# Description #

Get the next element in the cursor.

The optional unnamed argument specifies whether to wait for the next available element and how long to wait:

* `true`: Wait indefinitely (the default).
* `false`: Do not wait at all. If data is immediately available, it will be returned; if it is not available, a `Timeout::Error` will be raised.
* number: Wait up the specified number of seconds for data to be available before raising `Timeout::Error`.

The behavior of `next` will be identical with `false`, `nil` or the number `0`.

Calling `next` the first time on a cursor provides the first element of the cursor. If the data set is exhausted (e.g., you have retrieved all the documents in a table), a `StopIteration` error will be raised when `next` is called.

__Example:__ Retrieve the next element.

```rb
cursor = r.table('superheroes').run(conn)
doc = cursor.next()
```

__Example:__ Retrieve the next element on a [changefeed](/docs/changefeeds/ruby), waiting up to five seconds.

```rb
cursor = r.table('superheroes').changes().run(conn)
doc = cursor.next(5)
```

__Note:__ RethinkDB sequences can be iterated through via the Ruby [Enumerable][it] interface. The canonical way to retrieve all the results is to use an [each](../each/) command or [to_a()](../to_array/).

[it]: http://ruby-doc.org/core/Enumerable.html
17 changes: 17 additions & 0 deletions api/ruby/index.md
Expand Up @@ -156,6 +156,23 @@ conn.noreply_wait

{% apisection Cursors %}

## [next](next/) ##

{% apibody %}
cursor.next([true])
{% endapibody %}

Get the next element in the cursor.

__Example:__ Retrieve the next element.

```rb
cursor = r.table('superheroes').run(conn)
doc = cursor.next()
```

[Read more about this command →](next/)

## [each](each/) ##

{% apibody %}
Expand Down

0 comments on commit a393c80

Please sign in to comment.