goio
goio copied to clipboard
Resource management in streams
Currently streams can only use resources provided at the top level via ordinary resource.Use
.
Sometimes we need to pass streams around and we wish that resources are correctly released when stream is either finished or thrown away.
This requires adding a finalizer to all stream steps. Then in every stream executor, these finalizers should be respected and appended to io
.
Signature might look like
stream.Finally[A any](stm stream.Stream[A], func () io.IOUnit) stream.Stream[A]
There are two FStreams - one that is just a pair of stream and IO to finalize, and another one - IO of such pair. The difference is that IO represents a stream that has not yet been started.