I want to use a function similar to take(n: Int)
but in a time dimension:
consume(period: Duration
. So I want a stream to terminate if a timeout occurs. I know that I could compile a stream to something like IO[List[T]]
and cancel it, but then I'll lose the result. In reality I want to convert an endless stream into a limited one and preserve the results.
More on the wider scope of the problem. I have an endless stream of events from a messaging broker, but I also have rotating credentials to connect to the broker. So what I want is to consume the stream of events for some time, then stop, acquire new credentials, connect again to the broker creating a new stream and concatenate two streams into one.