rethinkdb / rethinkdb/docs

Declaring the callback for `next` ouside the callback of `run`.

Open
#519 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
118
Forks
161
PR merge metrics
No merged PRs in 30d

Description

The current example relies on the fact that fetchNext is declared in the callback of run.

Users can create a unique callback with something like that:

var fetchNext = function(err, row) {
     if (err) {
            if (((err.name === "RqlDriverError") && err.message === "No more rows in the cursor.")) {
                console.log("No more data to process")
            }
            else {
                // handle error
            }
     }
     else {
        // process row
        this.next(fetchNext.bind(this));
    }
}

// later they can do:
query.run(connection, function(err, cursor) {
     if (err) {
         // handle error
    }
    else {
        cursor.next(fetchNext.bind(cursor));
    }
})

Not so many people use next with a cursor, but this can be useful if users want to open multiple feeds on different end points, and always stream back the changes in the same way.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Find the current documentation example that uses query.run with a cursor and cursor.next. Compare it with the issue's standalone fetchNext callback pattern, then update the example or surrounding explanation to cover declaring the callback outside run. Done means users can understand how to reuse the callback for multiple feeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.