docs icon indicating copy to clipboard operation
docs copied to clipboard

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

Open neumino opened this issue 11 years ago • 0 comments

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.

neumino avatar Sep 23 '14 17:09 neumino