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

Allan Wang

09/27/2018, 8:49 PM
Do flyweight patterns exist in coroutines? For example, let's say I have 5 suspend methods that require a parameter, which can also be retrieved by a suspend method. If I call two of them simultaneously, is there a way for me to have them wait on the same suspension? One way of doing this would be to keep a map of keys to deferred values, where I assume that calling await twice will only run the logic once. Is there a better way of achieving that?
b

bdawg.io

09/28/2018, 3:56 AM
That's literally what you get by using
async
and then calling
await()
on the same deferred object
If you do a Lazy dispatched
async
you can spawn them all off immediately and then the
async
won't start until the first
await()
invocation
3 Views