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

roy

08/30/2019, 7:49 AM
Hi, what is the canonical way to create a flow that replays its history whenever it's subscribed to? I have a Flow<String> that contains some log lines and whenever someone calls my API I'd like it to publish all previous log lines and additionally any new ones, by returning the flow as a server-sent event
o

octylFractal

08/30/2019, 9:50 AM
a flow can't replay its history, but every time you run a terminal operation it will rerun the original flow. you'd have to make that source replay all data somehow
r

roy

08/30/2019, 2:27 PM
Yes, I saw those issues, but I thought I was just fundamentally misunderstanding the issue. It's fine if I need to keep the original data around somewhere, but I was wondering how to connect the 'previously sent data' to the newly available data. More specifically, how to join the old data with the new data coming from a
callbackFlow
but I guess that's just doing a
concat
on them
4 Views