Skip to content

demos/counter: introduce server and improve code readability - #1505

Closed
Jaana Dogan (rakyll) wants to merge 1 commit into
agent-substrate:mainfrom
rakyll:counter
Closed

demos/counter: introduce server and improve code readability#1505
Jaana Dogan (rakyll) wants to merge 1 commit into
agent-substrate:mainfrom
rakyll:counter

Conversation

@rakyll

@rakyll Jaana Dogan (rakyll) commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

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 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.

@rakyll
Jaana Dogan (rakyll) force-pushed the counter branch 3 times, most recently from bd7a3ed to b530e6f Compare September 4, 2026 22:49
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.
@rakyll

Copy link
Copy Markdown
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.

@rakyll

Copy link
Copy Markdown
Collaborator Author

See #1506 instead.

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.

3 participants