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

Add stream method for non-destructive reading #562

Open
1 task done
agronholm opened this issue May 2, 2023 · 0 comments
Open
1 task done

Add stream method for non-destructive reading #562

agronholm opened this issue May 2, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@agronholm
Copy link
Owner

Things to check first

  • I have searched the existing issues and didn't find my feature already requested there

Feature description

Sometimes applications or protocol implementations would benefit from the ability to see if there's data ready for reading from the stream, but without actually removing said data from the buffer. For socket streams, this could be implemented using recv() with the MSG_PEEK flag. This should work on all platforms. For TLS streams, this is also doable but a tad more complex. One consideration would be that the stream might not return the same result when a destructive read is done after a non-destructive read with a yield point in between, but I think this could just be documented (and can be avoided by not sharing the stream among tasks in the first place).

Use case

This was mainly inspired by redis-py wanting to defensively check if the stream has any more data to be read. That said, I've come across other cases which I can't quite remember, where the knowledge of pending incoming data would help optimize the operation of a protocol implementation.

@agronholm agronholm added the enhancement New feature or request label May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant