https://kotlinlang.org logo
#coroutines
Title
# coroutines
g

genovich

09/02/2020, 9:01 AM
Hi, I want to define list of operations that will be executed later. What is better solution in this case? •
List<Deffered<T>>
List<suspend () -> T>
👍 2
o

octylFractal

09/02/2020, 9:02 AM
`Deferred`s are usually already executed, unless you start them as LAZY
so in general I would think the latter better represents it
g

genovich

09/02/2020, 9:03 AM
cool, thank you
btw, should I use
Flow
, if I want this operation to produce multiple values?
o

octylFractal

09/02/2020, 9:05 AM
are you thinking like
List<Flow<T>>
or just a
Flow<T>
? either works, they're just slightly different
g

genovich

09/02/2020, 9:05 AM
the first one
o

octylFractal

09/02/2020, 9:06 AM
unlike
Deferred
,
Flow
is usually cold/lazy, so I think using it directly is correct there
g

genovich

09/02/2020, 9:08 AM
ok, and if I want to create a constructor-function for that suspend-functions, should it look like
fun x(): suspend () -> T
? Or there may be a better syntax?
o

octylFractal

09/02/2020, 9:09 AM
I think that's the syntax, yes
g

genovich

09/02/2020, 9:16 AM
Thank you a lot for your time!
5 Views