Skip to content

Commit

Permalink
Replace hasNext with next - Fix #45
Browse files Browse the repository at this point in the history
  • Loading branch information
neumino committed Sep 23, 2014
1 parent 919d575 commit ea4eace
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chateau",
"version": "0.3.11",
"version": "0.3.12",
"description": "Data explorer for RethinkDB",
"main": "app.js",
"directories": {},
Expand Down
41 changes: 22 additions & 19 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,29 +343,32 @@ module.exports = function(configFile) {



stream.emit('data', '[')
var fetchNext = function(cursor) {
if (cursor.hasNext() === true) {
cursor.next( function(error, data) {
if (init === true) {
stream.emit('data', JSON.stringify(data))
init = false;

r.db(db).table(table).run( connection, {timeFormat: 'raw'}, function(error, cursor) {
if (error) {
handleError(error);
}
else {
stream.emit('data', '[')
var fetchNext = function(err, row) {
if (err) {
stream.emit('data', ']')
stream.emit('close')
}
else {
stream.emit('data', ','+JSON.stringify(data))
if (init === true) {
stream.emit('data', JSON.stringify(row))
init = false;
}
else {
stream.emit('data', ','+JSON.stringify(row))
}
console.log(this)
cursor.next(fetchNext);
}
fetchNext(cursor)
})
}
else {
stream.emit('data', ']')
stream.emit('close')
}
cursor.next(fetchNext)
}
}

r.db(db).table(table).run( connection, {timeFormat: 'raw'}, function(error, cursor) {
if (error) handleError(error);
fetchNext(cursor)
})
}
exports.importTable = function (req, res) {
Expand Down

0 comments on commit ea4eace

Please sign in to comment.