- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
kotlinx-coroutines-reactive
使 org.reactivestreams.Publisher
有awaitXXX
方法:
val person = peopleReactiveRepository.findById(personId).awaitSingle()
ExceptionHandler
无法将此异常转换为用户友好的响应。
java.util.NoSuchElementException: No value received via onNext for awaitSingle
at kotlinx.coroutines.experimental.reactive.AwaitKt$awaitOne$$inlined$suspendCancellableCoroutine$lambda$1.onComplete(Await.kt:131) ~[kotlinx-coroutines-reactive-0.22.1.jar:na]
at reactor.core.publisher.StrictSubscriber.onComplete(StrictSubscriber.java:123) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:1327) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onComplete(FluxHide.java:137) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:130) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.MonoNext$NextSubscriber.onComplete(MonoNext.java:96) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at com.mongodb.reactivestreams.client.internal.ObservableToPublisher$1.onComplete(ObservableToPublisher.java:78) ~[mongodb-driver-reactivestreams-1.6.0.jar:na]
val person = peopleRepository.findById(personId).awaitFirstOrDefault(null)
if (person == null) {
// do something
}
awaitSingleOptional
的方法。 .
最佳答案
没有标准Optional
Kotlin 中的包装器。您可以使用 the let
function对于此类情况:
val person = peopleRepository.findById(personId).awaitFirstOrDefault(null)?.let {
// do
}
null
,
let
调用也将评估为
null
.如果您需要处理这种情况,
Elvis operator可以使用:
.let {...} ?: throw IllegalStateException()
关于kotlin - 如何使用 kotlinx-coroutines-reactive 处理空场景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48617490/
我已经尝试了几个小时让 dokka 在 gradle 下工作,但我找不到任何能够解决依赖关系的版本组合。例如 ekolotyluk@MacBook-Pro microservices % ./grad
我正在使用 Android Studio Canary 构建一个新项目,并在为 Jet pack Compose 设置依赖项时将其作为构建输出: Execution failed for task '
我在应用程序中使用外部 API,而反序列化是使用 Kotlinx 序列化包完成的,当 api 结果是多个值的 Int 数组和单个值的原始 int 时,我遇到了问题。我怎样才能避免在此过程中崩溃。有没有
假设我正在上课: @Serializable data class MyClass( @SerialName("a") val a: String?, @SerialName("b")
我在应用程序中使用外部 API,而反序列化是使用 Kotlinx 序列化包完成的,当 api 结果是多个值的 Int 数组和单个值的原始 int 时,我遇到了问题。我怎样才能避免在此过程中崩溃。有没有
我正在尝试使用 kotlinx @Serializable,我遇到了这个问题: 我有以下类(class): @Serializable sealed class GrandParent 第二个: @S
我有一个 Json 输入,例如: { "type": "type_1", "data": { // ... } } data字段可能因 type 而异. 所以,我需要一个
这是我的 pojo 课 @Serializable data class Response( @SerialName("message") val message: String?,
如何使用 kotlinx 序列化来对可选字符串列表进行字符串化?我想执行类似的操作: val json = Json(JsonConfiguration.Stable) val data: List
字符串化时有没有办法忽略空值?当前它呈现为: “字段”:空 如果有一种方法可以根本不渲染空字段,那将是很好的-但我没有找到这样的选择。有人知道这怎么工作吗? 最佳答案 目前尚无法解决,但您可能需要跟踪
我正在为许多第三方 API 生成 JSON。他们中的许多人接受不同对象的列表(JSON 数组),但是,他们都不会接受 "type": "com.mycom.someclass"由于列表的多态性,由 k
我遇到了这样的错误 Unresolved reference: kotlinx 导入语句就像 kotlinx.android.synthetic.main.activity_main.* 粗体代码变为
尝试Kotlin,在项目中配置Kotlin,添加kotlin-android-extensions,还添加依赖项... import kotlinx.android.**synthetic**.mai
迁移到 AndroidX 后,我发现在一些中,并非所有类的 kotlinx.android.synthetic 字段现在都无法转换为实际类。 Widget has an unresolved type
我想制作一个自定义列表序列化程序,它将安全地解析无效的 json 数组。示例:Int 列表 [1, "invalid_int", 2] 应解析为 [1, 2]。我已经制作了一个序列化器并将其添加到 J
如果我没有指定任何内容,协程默认范围如何工作。让我们看一下这个例子: class MyAppCompatActivity:AppCompatActivity{ fun getContact() {
我正在使用 Java 8 的 LocalDatetime 转换一些代码使用 kotlinx-datetime 中的版本而且我找不到任何格式化方法。具体来说,我正在替换 FormatStyle.MEDI
我有一个为网络流量序列化的类。 @Serializable data class Packet(val dataType: String, val payload: Any) 我已经使用 Jav
安卓工作室 3.6 在一个屏幕上,我通过协程进行轮询,如下所示: fun initPoll() = viewModelScope.launch(Dispatchers.M
我注意到代码库中有以下函数,它使用 kotlinx html ,而且很难完全理解: private fun Tag.xrefImpl(prop: KMutableProperty0) = t
我是一名优秀的程序员,十分优秀!