demos/counter: introduce server and improve code readability - #1505
Closed
Jaana Dogan (rakyll) wants to merge 1 commit into
Closed
demos/counter: introduce server and improve code readability#1505Jaana Dogan (rakyll) wants to merge 1 commit into
Jaana Dogan (rakyll) wants to merge 1 commit into
Conversation
Jaana Dogan (rakyll)
force-pushed
the
counter
branch
3 times, most recently
from
September 4, 2026 22:49
bd7a3ed to
b530e6f
Compare
Encapsulate mutable state into a `server` struct that implements `http.Handler`, eliminating package-level global variables. Move `main()` to the top of the file for immediate entrypoint readability and clean up naming across struct fields and helper methods. Also improve listener initialization by binding sockets synchronously before spawning background worker goroutines, and replace the leaking `time.Tick` with `time.NewTicker`. Follow up: We are testing some features through this demo but we should remove them and keep this as a simple "increment" demo. When others read this demo, they should be able to focus on file based counter and how it's persisted.
Jaana Dogan (rakyll)
force-pushed
the
counter
branch
from
September 4, 2026 22:56
b530e6f to
2c4e664
Compare
Jaana Dogan (rakyll)
requested review from
Dmitry Berkovich (dberkov) and
Tim Hockin (thockin)
September 4, 2026 22:57
Jaana Dogan (rakyll)
marked this pull request as ready for review
September 4, 2026 22:57
Collaborator
Author
|
I'm actually going to close this for now. We should revisit this demo and simplify it. I'll send a follow up change for the ticker leak. |
Collaborator
Author
|
See #1506 instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While I reorganized the structure and naming, the file is still heavily overloaded with features, impacting overall readability. In this change:
Encapsulate mutable state into a
serverstruct that implementshttp.Handler, eliminating package-level global variables. Movemain()to the top of the file for immediate entrypoint readability and clean up naming across struct fields and helper methods.Also improve listener initialization by binding sockets synchronously before spawning background worker goroutines, and replace the leaking
time.Tickwithtime.NewTicker.Follow up: We are testing some features through this demo but we should remove them and keep this as a simple "increment" demo. When others read this demo, they should be able to focus on file based counter and how it's persisted.