How i can unsubscribe to a 'changefeed' in RethinkDB?

570 Views Asked by At

I know that i can subscribe for listen the changes on a table doing this

r.table('users').changes().run(conn, function(err, cursor) {
  cursor.each(console.log);
});

But, how i can stop to listen this changes? How i can unsubscribe for this changes?

1

There are 1 best solutions below

9
On

You can just call cursor.close(), (or you can do conn.close())

From the docs for cursor.close:

r. Closing a cursor cancels the corresponding query and frees the memory associated with the open request.

Additionally, closing the connection itself will automatically close all cursors associated with a connection. In other words, if you're closing connections properly, you usually won't need to explicitly close your cursors.

From the connection.close docs:

Closing a connection normally waits until all outstanding requests have finished and then frees any open resources associated with the connection. By passing false to the noreply_wait optional argument, the connection will be closed immediately, possibly aborting any outstanding noreply writes.