Using Deferred<…> in Room DAO with Kotlin Coroutines

亡梦爱人 提交于 2019-12-06 01:09:27

Your issue lies in that you're mixing the suspending converter and the Deferred converter. Use one or the other and your code will work as intended.

  • fun readMyObjectAsync(idMyObject: Int): Deferred<MyObject> - Best choice if you need to interface/be compatible with java code, since it doesn't require code transformations to actually function.
  • suspend fun readMyObjectAsync(idMyObject: Int): MyObject - If you're operating on pure kotlin this will allow better control through the context it is called in.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!