https://kotlinlang.org logo
Title
t

thana

01/10/2020, 1:34 PM
is there a convenience method that converts a
Mono
into a
Deferred
? I can see we can transofrm it into a
Flow
which feels wrong as the
Mono
provides at most one value
d

Dominaezzz

01/10/2020, 1:48 PM
At most? If it's not exactly one value, then
Deferred
also seems wrong.
t

thana

01/10/2020, 1:52 PM
well no. it IS excactly one value if successful: `A Reactive Streams 
Publisher
 with basic rx operators that completes successfully by emitting an element, or with an error.`
d

Dominaezzz

01/10/2020, 2:01 PM
Ah. (I'm not very familiar with Rx). But there's probably a
Mono.await()
suspend function or similar. It is discouraged to use the
Deferred
type, you just suspend instead (where possible).
☝️ 1
Just read the docs. It's called
awaitSingle()
.
a

Adam Powell

01/10/2020, 2:05 PM
Deferred
is more of a future, it's an operation already in flight. It's hot, not cold
☝️🏼 1
s

streetsofboston

01/10/2020, 2:14 PM
Depends, when started with
LAZY
, a Deferred is cold (but it's a 'shared' Mono/Single, since calling await() again won't restart the operation).
a

Adam Powell

01/10/2020, 2:20 PM
You can expose that same behavior as a suspend fun though, and just like a Single the shared/not shared nature of it is an implementation detail.
t

thana

01/10/2020, 2:22 PM
alright i understand. thanks for your input 🙂