小编Car*_*mer的帖子

相当于 Kotlin 协程流程中的 RxJava .toList()

我遇到一种情况,我需要观察 userId,然后使用这些 userId 来观察用户。userIds 或用户可能随时更改,我希望使发出的用户保持最新状态。这是我拥有的数据源的示例:


data class User(val name: String)

fun observeBestUserIds(): Flow<List<String>> {
    return flow {
        emit(listOf("abc", "def"))
        delay(500)
        emit(listOf("123", "234"))
    }
}

fun observeUserForId(userId: String): Flow<User> {
    return flow {
        emit(User("${userId}_name"))
        delay(2000)
        emit(User("${userId}_name_updated"))
    }
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我希望排放量为:

[User(abc_name), User(def_name)], 然后

[User(123_name), User(234_name)], 然后

[User(123_name_updated), User(234_name_updated)]

我想我可以在 RxJava 中实现这一点,如下所示:

observeBestUserIds.concatMapSingle { ids ->
    Observable.fromIterable(ids)
        .concatMap { id ->
            observeUserForId(id)
        }
        .toList()
}
Run Code Online (Sandbox Code Playgroud)

我应该编写什么函数来生成发出该信号的流?

kotlin rx-java kotlin-coroutines kotlin-flow

8
推荐指数
1
解决办法
2738
查看次数

CouchDB代理身份验证不起作用

当我向我的couchdb服务器发送一个http请求时,就像在CouchDB代理身份验证文档中显示的那样,它没有给出文档中显示的响应,只是空数据.我究竟做错了什么?

此外,我能够使用此代理身份验证启动会话吗?如果我尝试POST/_session,我会得到500个错误代码.

GET/_session HTTP/1.1
主机:127.0.0.2
:5984 User-Agent:curl/7.51.0
接受:application/json
Content-Type:application/json; charset = utf-8
X-Auth-CouchDB-UserName:john
X-Auth-CouchDB-Roles:blogger

<HTTP/1.1 200 OK
<Cache-Control:必须重新验证
<Content-Length:132
<Content-Type:application/json
<Da​​te:Sun,2016年11月6日01:10:58 GMT
<服务器:CouchDB/2.0.0 (Erlang OTP/17)
<{"ok":true,
"userCtx":{"name":null,"roles":[]},
"info":{"authentication_db":"_ users","authentication_handlers": [ "饼干", "默认"]}}

authentication proxy couchdb

5
推荐指数
1
解决办法
1918
查看次数