简体   繁体   中英

How to unSubscribe Changefeeds in RethinkDB? When changes is over

Cursor changeCursor = r.table("users").changes().run(conn);
for (Object change : changeCursor) {
    System.out.println(change);
}

I only need to know changes once. I know "changeCursor.close()" can stop feeds. The problem is how can i know the size of the changes this time!!

If three users added, "System.out.println(change)" execute thress times. If only one user added, "System.out.println(change)" execute one time. Then, i need to unSubscribe Changefeeds in RethinkDB.

changeCursor.toList();
changeCursor.iterator();

Not do anythings!

changeCursor.hasNext();

Alaways true!

I don't know the number of changes. I don't know when to execute the changeCursor.close() method.

I'm not really sure what you are asking. It seems you want to instantly get the first change, then close it.

You can do something like this with javascrip driver:

var r      = require('rethinkdb')

r.connect({
  host: 'localhost',
  port: 28015,
})
.then(function(conn) {
  return r.table('users').changes().run(conn)
})
.then(function(cursor) {
  cursor.next()
    .then(function(doc) {
      console.log(doc)
      //Ok, now right after we get the first doc, we will close the cursor
      cursor.close()
      // if we want, we can also close connection
      // cursor.close().then(conn.close())
    })
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM