Allow an inner handle to be hot-swapped from inside a callback. #49
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.
Hello!
I'd like to be able to swap out an inner handle for a new one from
inside a callback. This would allow me to test the connection and
replace it if necessary before dispatch. Currently, it's not possible.
This test script illustrates:
On my machine this produces:
The inner handle being used by the dispatcher was freed after my
callback exited because it had been associated with the newly-created
outer handle, which was garbage collected. I've patched the dispatcher
to detect this situation and update its internal state accordingly (h,
mg, imp_xxh). After applying the patch:
t/70callbacks.t has also been updated with a representative test case.
I've checked that no memory leaks have been introduced by running the
test snippet inside a loop while watching memory usage. I also ran it
in Xcode with all the memory-debugging features enabled, with no
issues reported.
Thanks for taking a look, and let me know if I missed anything.