Open HolgerKnublauch opened 7 years ago
+1 for a .close()
method
+1 for a .close()
method from me, too.
would anyone like to submit PR?
Would calling .close()
have to be mandatory or could it be made optional?
The rdfjs spec says:
Streams are used only in a readable manner. This requires only a single queue per stream, which simplifies implementations and doesn't have performance drawbacks, compared to writeable streams
What means "closing" exactly? In my opinion, if you close it manually, Streams wouldn't be readable-only anymore. Furthermore, what should happen, if there is a close function but its never called?
I suggest, that you leave that to the implementation. For instance, an iterator could implement a function, which is called, when the object itself gets removed. For instance, in PHP there is a __destruct function, which can be overridden and is called, before object removal. This way, you can remove the iterator manually the release its resources. Maybe there is something similar in Java.
Streams are read-only. By calling close, you signal that you will not read anymore, so no more resources need to be spent on generating items. Behind the scenes, for instance, HTTP connections could be closed, or file descriptors.
Sorry if this has been discussed before.
I am wondering how Streams (such as those returned by .match) are supposed to be walked and then, for example, stopped after the first element. Shouldn't there be some kind of a .close() function that releases the resources? As an example I am working on a Oracle Nashorn-based implementation of your API that runs a Jena Triple iterator in the background, and I need a clean way to call .close() on those Java objects. The contract would be that close() must be called unless the Stream is walked to exhaustion.