Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hub.init/initWith is Resource #1066

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

johnhungerford
Copy link
Contributor

Fixes #1044

Problem

Hubs are initialized with a long-running fiber that should be cleaned up when the hub is no longer being used. This PR makes the initializing methods init, initWith, and all overloads Resource effects, where the finalizer calls Hub#close.

Solution

Hub#initWith uses Resource.acquireRelease to construct the Hub and calls _.close.unit as the finalizer.

Notes

@@ -251,7 +251,9 @@ object Hub:
}
}
}.map { fiber =>
f(new Hub(channel, fiber, listeners))
Resource
.acquireRelease(new Hub(channel, fiber, listeners))(_.close.unit)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that should be fixed in a separate PR. This means some substantial changes to Resource

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, just making sure you knew!

@hearnadam hearnadam merged commit 58f9ae2 into getkyo:main Feb 4, 2025
3 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.

Hub.init/initWith should be Resource
3 participants