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 a blocking iterator utility for Vert.x read streams. #5493

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

vietj
Copy link
Member

@vietj vietj commented Feb 28, 2025

Motivation:

With virtual threads, it might be a common thing to adapt a Vert.x read stream to a blocking Java iterator. The primary use case of this is the gRPC blocking client generation.

Changes:

An iterator adapter for a Vert.x read stream.

The implementation uses java lock and lock conditions to let the producer thread signal consumer threads.

While the iterator should be consumed by a single thread (because of the hasNext/next racy sequence), the iterator is thread safe and tolerate multiple consumers.

The implementation consumer side is similar to a Java blocking queue and relies on lock conditions to signal state change to consumers.

@vietj vietj added this to the 5.0.0 milestone Feb 28, 2025
@vietj vietj self-assigned this Feb 28, 2025
Motivation:

With virtual threads, it might be a common thing to adapt a Vert.x read stream to a blocking Java iterator. The primary use case of this is the gRPC blocking client generation.

Changes:

An iterator adapter for a Vert.x read stream.

The implementation uses java lock and lock conditions to let the producer thread signal consumer threads.

While the iterator should be consumed by a single thread (because of the hasNext/next racy sequence), the iterator is thread safe and tolerate multiple consumers.

The implementation consumer side is similar to a Java blocking queue and relies on lock conditions to signal state change to consumers.
@vietj vietj force-pushed the read-stream-iterator branch from 9467fc4 to fa42f52 Compare February 28, 2025 15:47
@vietj vietj merged commit 5a23d05 into master Feb 28, 2025
7 checks passed
@vietj vietj deleted the read-stream-iterator branch February 28, 2025 18:13
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

Successfully merging this pull request may close these issues.

1 participant