-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add a NamedHandler, as well as the ability to remove handlers by their name. #47
Conversation
💕 UwU Nice! I've finally got some stuff to play with once my exams get over 😀 |
I've put this on hold for now, because I'm not satisfied with the fact these methods aren't thread-safe. On the other hand, I'm also not a fan of putting everything behind a RWMutex - I worry this would slow down update processing for many, when only a select few actually need to remove handlers. In my mind, if you need to "remove" handlers, you should use a custom handler and build logic into the Let me know here if you have any thoughts! |
@PaulSonOfLars you are right, this way it does have costs for both people who want the feature, and the ones who don't. A boolean config var indicating whether the user wants the feature to be enabled or not; how does it sound like? Let me know if this idea (or something like this) can solve the problem or not! (or, if there is a main problem behind it, other than this) |
I had a think about this, and the reason I didn't go with it is because that really smells of poorly designed code 😅 And would make it much easier to accidentally forget to use the right locks in the future. I see another option; make the What do you think? |
@PaulSonOfLars wow this sounds like a really really good option! |
Converting to an interface will induce some overhead (allocation). Also, there are alternatives to RWMutexes:
|
34f3202
to
276e400
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext/handler_mapping.go
Outdated
|
||
// Only one item left, so just delete the group entirely. | ||
if len(currHandlers) == 1 { | ||
m.handlerGroups = append(m.handlerGroups[:group], m.handlerGroups[group+1:]...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, once the lib is updated to go1.21, the delete element operations could be replaced with https://pkg.go.dev/slices#Delete. Easy to make a fatal slip with these 😂
This one seems fine, no fatal slips.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely agree - I was also uncertain about the thread safety of this, but the writemutex should ensure that we don't hit any weirdness here. Will wait a couple of months before moving to 1.21 and will make sure to add this when we do :)
ext/handler_mapping.go
Outdated
continue | ||
} | ||
|
||
m.handlerGroups = append(m.handlerGroups[:j], m.handlerGroups[j+1:]...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always feel uneasy when I have to modify the slice I'm iterating on. But I guess in this case it's ok, as you're returning immediately.
43a4bbf
to
ac58f3c
Compare
…ncurrent modification
ac58f3c
to
2f333e3
Compare
What
Add a NamedHandler handler, which wraps existing handlers and exposes a stable name to remove them by.
With that, add methods to remove handlers.
And finally... Add some tests to make sure they all work as expected!
Impact