首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在RethinkDB中unSubscribe Changefeeds?当更改结束时

如何在RethinkDB中unSubscribe Changefeeds?当更改结束时
EN

Stack Overflow用户
提问于 2016-05-07 20:35:42
回答 1查看 339关注 0票数 1
代码语言:javascript
复制
Cursor changeCursor = r.table("users").changes().run(conn);
for (Object change : changeCursor) {
    System.out.println(change);
}

我只需要知道更改一次。我知道"changeCursor.close()“可以停止提要。问题是我怎么知道这次变化的大小!

如果添加了三个用户,"System.out.println(change)“将执行三次。如果只添加了一个用户,"System.out.println(change)“将执行一次。然后,我需要在RethinkDB中unSubscribe Changefeeds。

代码语言:javascript
复制
changeCursor.toList();
changeCursor.iterator();

什么也不做!

代码语言:javascript
复制
changeCursor.hasNext();

总是正确的!

我不知道更改的次数。我不知道何时执行changeCursor.close()方法。

EN

回答 1

Stack Overflow用户

发布于 2016-05-08 03:22:42

我不太清楚你在问什么。您似乎希望立即获得第一个更改,然后关闭它。

您可以使用javascrip驱动程序执行以下操作:

代码语言:javascript
复制
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())
    })
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37088614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档