Slick 3.0-RC3 fails with java.util.concurrent.RejectedExecutionException

前端 未结 1 1056
星月不相逢
星月不相逢 2020-12-12 02:09

I\'m trying to get familiar with Slick 3.0 and Futures (using Scala 2.11.6). I use simple code based on Slick\'s Multi-DB Cake Pattern example. Why does the following code t

相关标签:
1条回答
  • 2020-12-12 02:33

    I think that something is not correct in what you are trying to do: Slick's run method doesn't return Unit and doesn't fail with an exception - as it used to in previous versions. run now returns a Future, so if you want to run actions in sequence you need to flatMap the steps, or use a for-comprehension:

    def init() = {
      val = results for {
        _ <- db.run(dal.create)
        _ <- db.run(dal.stuffTable += Stuff(23, "hi"))
        r <- db.run(dal.stuffTable.filter(_.serial === 23).result)
      } yield r
    }
    

    I am not sure that you really need to use db.close that way: that is actually what may be causing the error (i.e. the db is closed in concurrence with the future that runs the actual queries so the execution can't happen).

    If you want to handle errors use Future's capabilities, e.g.:

    result.onFailure { case NonFatal(ex) => // do something with the exception }
    
    0 讨论(0)
提交回复
热议问题