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

Improve docs to make it clear grants persist until released #74

Open
buzmeg opened this issue Sep 18, 2020 · 5 comments · May be fixed by #109
Open

Improve docs to make it clear grants persist until released #74

buzmeg opened this issue Sep 18, 2020 · 5 comments · May be fixed by #109
Labels
docs Documentation improvements

Comments

@buzmeg
Copy link

buzmeg commented Sep 18, 2020

Did I miss a way to test if the BBQueue is empty without actually pulling bytes?

If not, was there an architectural reason not to implement is_empty() on a Consumer?

Rationale for is_empty():

Sometimes I may want to check to see if there is something in the queue and then schedule the actual read for later/somewhere else. For example, I may want to set a flag in interrupt context or schedule a DMA sometime later.

Unfortunately, if I have to call read() I have to be ready in case the read comes back with a grant instead of InsufficientSize. Getting that grant to where it needs to be may not be very simple especially if the grant is only the first half of a read cut apart by inversion of the read/write pointers.

Thanks.

@jamesmunns
Copy link
Owner

Hey! I could implement this, though grants do not do anything when dropped without committing.

For example, this would do exactly what you want:

let data_pending = consumer.read().is_ok();

I'd also accept a PR that implements this directly though, without having to make a "throwaway grant".

@buzmeg
Copy link
Author

buzmeg commented Nov 12, 2020

Oh! So consumer.read() always returns the same thing until release() is executed (or until the producer commits something new)?

Somehow, I missed that. Presumably, that would just let me pull the grant, check it, set the flag, drop the grant, and then let the other thread pull another grant.

Thanks. Sorry about missing that.

@jamesmunns
Copy link
Owner

Hey @buzmeg, is it okay if I close this? Or would you like to see a change to add an is_empty() feature, or a docs update to make this more clear?

@buzmeg
Copy link
Author

buzmeg commented Dec 1, 2020

@jamesmunns Go ahead and close this. However, the docs/examples definitely need an example that you read() the same data until release().

@jamesmunns
Copy link
Owner

I'd definitely appreciate a PR if you have a chance! Otherwise I'll leave this open as a reminder.

@jamesmunns jamesmunns changed the title is_empty() method on Consumer? Improve docs to make it clear grants persist until released Dec 1, 2020
@Sympatron Sympatron linked a pull request Dec 9, 2024 that will close this issue
@Sympatron Sympatron added the docs Documentation improvements label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants