Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to .close() a stream? #4

Open
HolgerKnublauch opened this issue Jan 31, 2017 · 6 comments
Open

How to .close() a stream? #4

HolgerKnublauch opened this issue Jan 31, 2017 · 6 comments

Comments

@HolgerKnublauch
Copy link

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.

@RubenVerborgh
Copy link
Member

+1 for a .close() method

@jacoscaz
Copy link

+1 for a .close() method from me, too.

@elf-pavlik
Copy link
Member

would anyone like to submit PR?

@jacoscaz
Copy link

Would calling .close() have to be mandatory or could it be made optional?

@k00ni
Copy link

k00ni commented Nov 22, 2018

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.

@RubenVerborgh
Copy link
Member

RubenVerborgh commented Nov 22, 2018 via email

@elf-pavlik elf-pavlik transferred this issue from rdfjs/data-model-spec Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants