WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@cmsax
Copy link

@cmsax cmsax commented Jan 23, 2025

Description:

This PR refactors the HTTP server implementation in the ProgressBar to address issues with the global default HTTP server instance, which caused panics when creating multiple ProgressBar instances with HTTP servers. The changes introduce a dedicated HTTP server instance for each ProgressBar, enabling users to safely run and manage multiple servers.

Key Changes:

Replaced the global http.HandleFunc with isolated http.ServeMux instances per ProgressBar.

Added a new HTTPServer object returned by StartHTTPServer(), providing a Shutdown() method for graceful termination.

Benefits:

Prevents route conflicts between multiple ProgressBar instances.

Allows users to start and stop HTTP servers independently.

Ensures safer concurrent usage and better resource management.

@cmsax cmsax changed the title feat: allow user to shutdown progressbar http server instance feat: allow user to safely run and manage multiple progressbar http servers Jan 23, 2025
@schollz schollz merged commit 2236360 into schollz:main Jan 24, 2025
1 check passed
@schollz
Copy link
Owner

schollz commented Jan 24, 2025

Great work, 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