从rxjava

时间:2019-01-05 00:14:54

标签: rx-java

我有下一个方法,该方法返回一个Single:

override fun getNavItemById(dCSServiceContext: DCSServiceContext):Single<NavItem>{
        return scribeProvider.getNavItemById(dCSServiceContext).map{ navItem ->
            return@map scribePresenter.presentNativeItem(navItem)
        }
    }

但是我喜欢这个方法只返回对象,像这样:

override fun getNavItemById(dCSServiceContext: DCSServiceContext):NavItem{
        return scribeProvider.getNavItemById(dCSServiceContext).map{ navItem ->
            return@map scribePresenter.presentNativeItem(navItem)
        }// I need just the object in order to pass this result as a parameter to other method
    }

关于如何以一种优雅的方式做到这一点的任何想法?

非常感谢!

1 个答案:

答案 0 :(得分:0)

在流的末尾添加.blockingGet()应该可以解决问题。它将返回实际值,而不是Single

它应该看起来像这样

return scribeProvider.getNavItemById(dCSServiceContext)
.map { navItem -> return@map scribePresenter.presentNativeItem(navItem) 
}.blockingGet()