Run transactionally and retrieve result in Future

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 10:02:43
Roman

Coming from the other question you asked: You are opening and then immediately closing the db connection in the finally clause. Therefore your async db operation runs against a closed db connection. That's also why it works by using Await since that blocks the execution of db.close until you received the result set.

So how to fix this?

Either you move db.close into future.map or better you let play-slick handle db connections for you.

Side note

You should close your other question and update this thread accordingly instead.

Your second example is fine. My guess is that you are either running it in standalone program or in test - and it simply finishes before future has a chance to be executed.

Try to add some sleep after your code in your second sample and you'll see it is getting printed. This is definitely not something (this sleep) you would do in your actual code but it will show you it works as it should.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!