Closed tsebastiani closed 7 years ago
Hi @tsebastiani! I am not currently behind my Mac so I cannot check your code. Perhaps you can take a look at the test file (https://github.com/pixelspark/rethink-swift/blob/master/Tests/RethinkTests/RethinkTests.swift)? This shows the basic usage patterns. A slightly more complicated usage example is here: https://github.com/pixelspark/warp/blob/master/WarpConduit/Sources/RethinkStream.swift.
Hi @pixelspark, same issue here. Following your tests i'm not able to get it working. I establish the connection and everything seems to work perfectly, but when I run the following code:
R.db(db).table(table).changes().run(connection) { response in
print("Something changed")
}
The 'Something Changed' log is printed when connecting but never more, is that the right way of doing it?
Thanks a lot
@alextarrago does your program exit after the first message? The changes().run() command does not block nor keep the program alive by itself. As long as connection
is referenced and connected, it should work. Is your program running an NSRunLoop?
Thanks for the fast reply @pixelspark. I got it working later yesterday.
R.connect(URL(string: "rethinkdb://\(server):\(port)")!, user: user, password: password) { (err, connection) in
R.db(db).table(table).indexWait().run(connection) { (response) in
R.db(db).table(table).changes().run(connection) { response in
var consumeChanges: ((_ response: ReResponse) -> ())? = nil
consumeChanges = { (response: ReResponse) -> () in
if case ReResponse.rows(let docs, let cb) = response {
self.updateDocuments(response: response)
cb!(consumeChanges!)
}
else {
print("Received unexpected response for .changes request: \(response)")
}
}
consumeChanges!(response)
}
}
}
Hi, I'm trying to implement a realtime application with rethinkdb and your driver. What I would like to achieve as first task Is to connect to the database and wait for changes in a table. Actually the connection is fine but waiting for changes seems not to work. Do you have any example app that covers the basics of the driver? This is my code: ´´´ R.connect(URL(string: "rethinkdb://192.168.250.96:28015")!, user: "user1", password: "user1") { err, connection in assert(err == nil, "Connection error: (err)")
´´´ I would expect that any time I insert something in the table "There's a change!!" is printed in console , but that's not actually happening!
Thanks a lot.