These are needed to stop the generator - otherwise it would generate new events or update its value forever (there is also a function paused: () => Boolean but its purpose is different).
But right now all the methods inherited from EventStream/Signal return only a standard signal which means that the user needs to hold a reference to the original generator somewhere, to eventually stop it. This is okay in many cases but in soome others the user might want to create a complex generator and it would make sense to split into steps chained by .map, .flatMap, etc., and then just keep a reference to the final signal.
For this I can extract these two methods into a trait, Closeable and then overwrite those methods. (They would need to lose their final keyword...)
I could even create CloseableStream and CloseableSignal, instead of overwriting directly in generator classes. After all, from the outside it's only important that the event stream / signal can be closed, not that it's a generator.
It would also be a step connecting generators and Finite streams and signals. They will be automatically closeable, but they can inherit and modify Closeable anyway ... or not. Something to think about.
On top of that, the Closeable trait could inherit from java.lang.AutoCloseable, so maybe I could in future use it in try-with-resources ?...
GeneratorStream
andGeneratorSignal
have methods:These are needed to stop the generator - otherwise it would generate new events or update its value forever (there is also a function
paused: () => Boolean
but its purpose is different). But right now all the methods inherited from EventStream/Signal return only a standard signal which means that the user needs to hold a reference to the original generator somewhere, to eventually stop it. This is okay in many cases but in soome others the user might want to create a complex generator and it would make sense to split into steps chained by.map
,.flatMap
, etc., and then just keep a reference to the final signal.For this I can extract these two methods into a trait,
Closeable
and then overwrite those methods. (They would need to lose theirfinal
keyword...) I could even createCloseableStream
andCloseableSignal
, instead of overwriting directly in generator classes. After all, from the outside it's only important that the event stream / signal can be closed, not that it's a generator. It would also be a step connecting generators andFinite
streams and signals. They will be automatically closeable, but they can inherit and modifyCloseable
anyway ... or not. Something to think about. On top of that, theCloseable
trait could inherit fromjava.lang.AutoCloseable
, so maybe I could in future use it in try-with-resources ?...