how to i take the first element fro ma flow and th...
# coroutines
n
how to i take the first element fro ma flow and then consume the rest with collect ? seems like when i use
take
it closes the flow
l
withIndex + collect and destructuring
n
ohh, smart
that is a bit akward because i want to get the login info from the first websocket frame and need to then use the security context for the rest of the code
l
If you have a better idea about the API you want, I guess it's relatively easy to implement it yourself
n
how can i implement taking one value out a flow without cancelling it ? that seems to be the main issue.. and that spring + reactor types are involved possibly
l
By using
collect
collect
is the base of every flow operator
You can also use
shareIn
or
stateIn
n
when i use shareIn i can then call
first()
and
.skip(1).collect()
later correct ? or do i need to ensure it has a buffer for that ?
l
It depends on the timing, but probably
n
the first message should be there instantly.. the other ones could come later.. i will jsut try this
this seemed to have worked, thx
👍 1
d
Could always
produceIn
and
receive()
the items manually.
👍 1
l
Ah yes, very true, you can do something like that:
Copy code
yourFlow.produceIn(someScope).consume {
    receive() // First value
    receiveAsFlow().collect { // Other values
    }
}