Skip to content

Conversation

@lbialy
Copy link
Contributor

@lbialy lbialy commented Nov 2, 2025

No description provided.

impossible to interrupt such operations directly. This pattern extends to other similar blocking operations that behave
like stdin.

The solution is to delegate the blocking operation to a separate thread and use a [channel](../streaming/channels.md)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome that you remembered - thanks! :) Maybe it would also be good to mention why the thread needs to be manually created, not Ox-managed (that is, not created through fork)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Note that for better stdin performance, you can use `Channel.buffered` instead of a rendezvous channel, or even use
`java.lang.System.in` directly and proxy raw data through the channel. Keep in mind that this solution leaks a thread
that will remain blocked on stdin for the lifetime of the application. It's possible to avoid this trade-off by using
libraries that employ JNI/JNA to access stdin, such as JLine 3, which can use raw mode with non-blocking or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a link on how to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meaning how to use jline3 or how it uses raw mode with O_NONBLOCKING or VTIME=1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a link to JLine 3 - maybe an appropriate docs page, or anything that would help people use it in a project

@lbialy
Copy link
Contributor Author

lbialy commented Nov 5, 2025

@adamw done

@adamw
Copy link
Member

adamw commented Nov 10, 2025

Thanks! :)

@adamw adamw merged commit fd7aa9c into softwaremill:master Nov 10, 2025
6 checks passed
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.

2 participants