0

I have a simple database in which I insert messages. I use the the change() method with the squash option to get the new messages every 10 seconds:

  r.table('wall_posts').orderBy({
    index: r.asc('date')
  }).limit(100).changes({
    squash: 10
  })...

I want to get a new array of the new messages every 10 seconds. I know the output of this cursor is infinite.
Is there a way to get an array by detecting the moment where the cursor will block until more elements are available? (or any other way)

Thanks

1 Answers1

0

To answer below question:

Is there a way to get an array by detecting the moment where the cursor will block until more elements are available? (or any other way)

Cannot you do this outside RethinkDB level? Whenever cursor have new data, you can push it into some other callback to create an array.

But I think:

When you are saying you want to get new message every 10 seconds, what blocks you from doing something like this:

setInterval(function() {
    r.table('wall_posts').orderBy({
        index: r.asc('date')
    }).limit(100)
}, 10000)

The way you use index date make me that you only want to get latest post. If that the case, I think you don't event have to use changes here.

If, for example, you have an UI where you want whenever a new message comes up, updating the UI with new message, that's what changes is for.

kureikain
  • 2,304
  • 2
  • 14
  • 9
  • Yes I ended up using a very similar solution where I use an array as buffer that I empty every 10 seconds. I use `changes` to monitor change (the read operations come from several different queries, so it's easier for me to use a changes()). Then I use the result to notify the clients (not only the client who send the message) – Matthias Aug 16 '15 at 16:27