Closed gmethvin closed 9 years ago
Nice catch, I'll push an snapshot for this tomorrow.
Also in the mean time you can use an Async connection and do the following\
import com.rethinkscala.Async._
block{
implicit c:BlockingConnection=>
import c.delegate._
r.tableAs[Foo].insert(....).run
}
or
val result:Either[RethinkError,InsertResult] = block(r.tableAs[Foo].insert(....))
I'll be sure to update the wiki for this as well.
@kclay Thanks. So it'll be possible to have multiple connection instances now? In my case it's not absolutely necessary, but it would be if you had connections to two different database hosts.
My workaround was just to use the async connection and call Await.result
(since in my case this is in initialization code where exceptions should be fatal).
@gmethvin Correct right now its not possible to have multiple connection instances but you can alleviate the need of explicitly using Await.result by using one of the examples above in your code that needs to block.
@gmethvin did you get to check out the recent 0.4.8-SNAPSHOT
It seems like that works. Thanks.
I wanted to do a few initialization tasks with a
BlockingConnection
and all other queries with anAsyncConnection
. My instances were created as follows:If I run queries on both, I will sometimes get the wrong result returned on one or more of my queries, and usually get an error like
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double
when trying to use the result of a query (since the other query was for something completely different).I suspect there is some shared global state that's causing this, maybe the cache here? https://github.com/kclay/rethink-scala/blob/master/core/src/main/scala/com/rethinkscala/net/CursorFactory.scala#L16
Note that this also happens with two async connections. So I suppose maybe this library just doesn't support using multiple connection instances in the same JVM. If that's the case, I'd prefer to have an explicit check and throw an exception on initialization so I know this ahead of time.