Skip to content

Make the Basic Event Loop example show the flow of control - #208

Merged
ioquatix merged 2 commits into
socketry:mainfrom
yukik8:make-basic-event-loop-show-flow
Aug 6, 2026
Merged

Make the Basic Event Loop example show the flow of control#208
ioquatix merged 2 commits into
socketry:mainfrom
yukik8:make-basic-event-loop-show-flow

Conversation

@yukik8

@yukik8 yukik8 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

When I read the Basic Event Loop example for the first time, I couldn't tell what it was demonstrating: the final output is identical to what blocking IO would produce, and the most important fact — that io_wait suspends the reader without blocking the program — is not visible anywhere in the output.

This PR tries to make the flow of control visible:

  • [main] / [reader] / [writer] labels show which fiber each line comes from.
  • Comments mark exactly where the reader suspends and where execution resumes.
  • The expected output shows [main] lines appearing while the reader is waiting — an ordering that would be impossible with blocking IO.

I verified the example runs unchanged on Ruby 3.4.10 (macOS arm64) and produces exactly the output shown. (This also sidesteps the Hash#inspect format issue addressed in #207, since the example no longer prints a Hash.)

Open question: I'm genuinely unsure about the trade-off — this version is much longer than the original 12 lines. Would you prefer:

  • (a) this fully annotated version,
  • (b) a shorter version with fewer log lines, or
  • (c) keeping the original code and only adding an expected-output block?

Happy to rework it in any direction.

Types of Changes

  • Maintenance.

Contribution

Signed-off-by: yukik8 <andres8.yuuki@gmail.com>
@yukik8
yukik8 marked this pull request as ready for review August 5, 2026 06:30
@ioquatix
ioquatix merged commit 758917b into socketry:main Aug 6, 2026
@ioquatix

ioquatix commented Aug 6, 2026

Copy link
Copy Markdown
Member

Thanks for your suggestion, I made some minor refinement to make the output more concise, but overall this is a big improvement. Thanks.

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